jQuery datepicker only works once and is not shown the second time -
asp.net mvc3 / jquery 1.9.1 / jquery ui 1.10.2
i've got page on open modal dialog after clicking on ajax.actionlink
. inside dialog have input field , datepicker
associated it. when open dialog first time, can click on datepicker button (or inside associated input field receives focus, showon
set both
), , datepicker shows expected. can, while modal dialog open, want to, datepicker shows every time. when close modal dialog (via attached $("ui-widget-overlay").click(function(){...});
, open again, datepicker no longer works, no matter whether try click on button or associated input field.
i tried debug jquery code, , both times lines of code being run same (and though datepicker doesn't show second time dialog opened, jquery methods triggered) can see in debugger. i'm stumped, , methods described in this post helped in terms of being show datepicker first time dialog opens. another post seems related misunderstanding how showon
setting works.
i tried destroy datepicker via $("#datepicker").datepicker("destroy");
when closing dialog - no avail. ideas?
update
on "calling page":
$(document).ready(function () { $("#popupdialog").dialog( { autoopen: false, modal: true, open: function() { $("ui-widget-overlay").click(function() { $("#popupdialog").dialog("close"); } } }); }); [...] @ajax.actionlink( "some text", "action", "controller", new ajaxoptions { httpmethod = "get", updatetargetid = "popupdialog", insertionmode = insertionmode.replace, onsuccess = "openpopup()" }) [...] function openpopup() { $("popupdialog").dialog("open"); } [...] <div id="popupdialog" style="display: none;"></div>
the controller action simple , follows:
public actionresult action() { myactionmodel myactionmodel = new myactionmodel(); return partialview( myactionmodel ); }
after more debugging , attempts trace jquery events, tested whether problem existed jquery ui 1.9.2, didn't. compared relevant datepicker
code lines did not involved many actual changes.
to put long story short, problem described in question above fixed changing single line of code 1.10.2 in 1.9.2:
1.10.2 causing problems
/* initialise date picker */ if (!$.datepicker.initialized) { $(document).mousedown($.datepicker._checkexternalclick); $.datepicker.initialized = true; }
1.9.2. version, working expected
/* initialise date picker */ if (!$.datepicker.initialized) { $(document).mousedown($.datepicker._checkexternalclick) // !!!!!!!!!! // next code line has added again date picker // shows when popup opened more once without reloading // "base" page. // !!!!!!!!!! .find(document.body).append($.datepicker.dpdiv); $.datepicker.initialized = true; }
i'm still not sure why behaviour exists, seems relatively rare constellation. note: didn't "reinitialize" datepicker
after opening popup dialog (or requesting partialview
via ajax), having single script source part of _layout.cshtml
sufficient. hope helps else.
Comments
Post a Comment