Mark W
Mark W

Reputation: 5964

jquery deselecting radio button bug

Jquery is deselecting my radio button which is in a dialog when another dialog is also opened. Running through in debug, the culprit in the jquery source is this line:

if ( !eventHandle ) {
  elemData.handle = eventHandle = function() {
    // Handle the second event of a trigger and when
    // an event is called after a page has unloaded
    return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
    jQuery.event.handle.apply( eventHandle.elem, arguments ) :
    undefined;//after this line executes selected radio button is lost.
  };
} 

does anyone know why this is?

simplified version of what is causing this:

$("#editYes").click(function(){//this radio is inside a dialog
  if($("#editsList").children().size()==0){
    $('#editDialogDiv').dialog('open');
    setDateHints();
    $('#editOpen').val("true");
  }
  //jquery code above runs here. Upto this point the radio remains selected
}); 

html is something like this:

<div title="atitle" id="dialog1">
...
 Yes<input id="editYes" type="radio" value="true" name="edits"> <!-- click this to open second dialog, but its then deselected by jquery-->
 No<input id="editNo" type="radio" value="false" name="edits">
...
</div>
<div title="anothertitle" id="secondDialog">
...some content
</div>

Upvotes: 0

Views: 130

Answers (1)

ericosg
ericosg

Reputation: 4965

Try using the change event and not the click since your issue is the order in which the actions take place.

Using the click does not register the change until your event ends. However, your event carries to a new window and loses the returning change action. Using change will register the change to your input, then process your actions.

Upvotes: 1

Related Questions