Yii Framework Forum: Click event on checkbox doesn't function on IE - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Click event on checkbox doesn't function on IE Rate Topic: -----

#1 User is offline   fhelix72 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 22-April 09
  • Location:Italy - Vicenza

Posted 23 March 2010 - 10:46 AM

Good morning, I have a checkbox defined with this instruction:

echo CHtml::activeCheckBox('myClass', 'myField', array('submit'=>Yii::app()->getRequest()->url));


when the checkbox is changed it should submit the form, but it does nothing with Internet Explorer while it functions perfectly in Firefox. It was also functioning with Internet Explorer with Yii version 1.1.0 before I upgrade to Yii 1.1.1.

I think the problem is related to upgrade of jquery to 1.4.2, if I see the code now it generate a code like this:

jQuery('#myClass_myField').live('click',function(){jQuery.yii.submitForm(this,'/myUrl',{});return false;});


instead in 1.1.0 this was the code:

jQuery('#myClass_myField').click(function(){jQuery.yii.submitForm(this,'/myUrl',{});return false;});


As I'm not a Jquery expert I don't understand if it's a Jquery bug or it is caused by an incorrect use in Yii.
Thanks for help.
0

#2 User is offline   Fran├žois Gannaz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 87
  • Joined: 24-November 09

Posted 24 March 2010 - 08:05 AM

You should give your IE version.

If I remember well, live() has some known problems. Some events (e.g. "change") don't work on all browsers, it may be the same for "click". So I guess it's a jQuery bug.

But I don't know why Yii produces such js code: the activeCheckBox isn't added dynamically, so I see no reason to use live() instead of click(). Well, that's just my thoughts, there's probably a good reason that I can't see.
0

#3 User is offline   fhelix72 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 22-April 09
  • Location:Italy - Vicenza

Posted 24 March 2010 - 09:32 AM

View PostFran├žois Gannaz, on 24 March 2010 - 08:05 AM, said:

You should give your IE version.

If I remember well, live() has some known problems. Some events (e.g. "change") don't work on all browsers, it may be the same for "click". So I guess it's a jQuery bug.

But I don't know why Yii produces such js code: the activeCheckBox isn't added dynamically, so I see no reason to use live() instead of click(). Well, that's just my thoughts, there's probably a good reason that I can't see.

I'm using internet explorer 6 (because my company still use this old version), I don't have at the moment the possibility to test on a newer explorer version.
0

#4 User is offline   fhelix72 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 22-April 09
  • Location:Italy - Vicenza

Posted 24 March 2010 - 11:29 AM

I found that to cause the problem is the presence in the same form of an activeDropdownlist:
echo CHtml::activeDropDownList('myClass', 'myDrop', array('sc1'=>'value1', 'sc2'=>'value2'), array('submit'=>'', 'prompt'=>'Choose..'));  


that generate this Jquery code:
jQuery('#myClass_myDrop').live('change',function(){jQuery.yii.submitForm(this,'',{});return false;});

The change event on the dropdownlist functions with no problem but it seems in Internet Explorer to go in conflict with the checkbox because if I comment the dropdownlist the click event on checkbox return to function again
I don't know the reason and how to solve the problem.
0

#5 User is offline   fhelix72 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 22-April 09
  • Location:Italy - Vicenza

Posted 25 March 2010 - 11:44 AM

At the end I solved the problem by changing the activeCheckBox from this

echo CHtml::activeCheckBox('myClass', 'myField', array('submit'=>Yii::app()->getRequest()->url));

to this:
  echo CHtml::activeCheckBox('myClass', 'myField', array('onclick'=>'this.form.target="_self";  this.form.action="'.Yii::app()->getRequest()->url.'"; this.form.submit();'));


So I eliminated the attribute 'submit' and I managed manually the submit with javascript on the 'onclick' event.

In this way it functions in all browsers, I hope this will be useful to others.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users