jQuery event triggers -
i have select box onchange listener. functions 100% when human uses it.
i've added modal dialog jqueryui create new option on said list. works 100% well.
however, upon adding said new option list, trying 'fake' change event trigger user doesn't have it. never seems fire.
can use trigger this?
//##### addc ####// $( "#add" ).click(function(){ $( "#addform" ).dialog({ autoopen: true, height: 200, width: 350, modal: true, buttons: { "add": function() { var f = $('#folder').val(); var request = $.ajax({ url: "process.it" , type: "post" , data: { f : f } }); request.done(function(msg) { $("#version").append( $('<option></option>').val(msg).html(msg) ).val(msg); $("#version").focus(); }); $( ).dialog( "close" ); }, cancel: function() { $( ).dialog( "close" ); } }, close: function() { $('#version').trigger('change'); } }); return false; }); //###### change ############### $('#version').change(function() { var promise = getfolders(mypath); promise.success(function (data) { promise.done(function(msg) { if(msg=="false"){ //error check } else { var myoptions = msg.split(","); var myselect = $('#version'); myselect .find('option') .remove() .end(); $.each(myoptions, function(x,y) { if(x==0){ x=-1; y="select version"; myselect.append($('<option></option>').val(x).html(y)); } else { myselect.append($('<option></option>').val(y).html(y)); } }); myselect.focus(); } }); }); });
i've pulled out ton of code, if there's brackets out of place, typos here show core of function. again, both work save adder calling changer:
the key line is:
close: function() { $('#version').trigger('change'); }
html looks like
<select id="version"></select> <a href="#" id="add">
when modal closes (or other place), want fire onchange re-pull source (the promise ajax lookup, function not listed here...) instead of now, append option list , select it.
i've tried trigger block of code in places , still won't fire.
so, how fake onchange system? i'm using modern build of both jquery , ui (maybe 1 point release out)
i think triggering change before response server. if want trigger change after the, have add method close dialog in 'done' function.
buttons: { "add": function() { var f = $('#folder').val(); var request = $.ajax({ url: "process.it" , type: "post" , data: { f : f } }); request.done(function(msg) { $("#version").append( $('<option></option>').val(msg).html(msg) ).val(msg); $("#version").focus(); $( ).dialog( "close" ); }); },
here example - http://jsfiddle.net/amz3n/2/
Comments
Post a Comment