.datapicker("open") not sure what that does since it is not in the api and it throws an error? you do not have that in your test page or in your init response to me
plus .datapicker() worked just fine. the unbind is because I had read that on some other thread as a solution to my problem, your are correct on that it is not needed.
anyway the solution has to do with MVC and controller when I do this for the Ajax loaded content it works the first time but after reopening the date picker doesn't work again. I tried your code I copied it from your post into my page and it didn't work. with the controller like this below
- public ActionResult testAjaxload()
- {
- return View();
- }
once i Changed the controller to the code below your code work :) I then tried to create the date picker with out the open and it worked since I couldn't find it in the api I used this .datapicker() . I also tried it with the unbind and it still worked all thought it is unneeded.
- public ActionResult testAjaxload()
- {
- return PartialView();
- }
the cleaned up script I finished with
- <script type="text/javascript">
- var modaldia;
- $(document).ready(function () {
- modaldia = $("#dialogModalCreate");
- modaldia.dialog({
- autoOpen: false,
- width: 750,
- modal: true
- });
- $("#model").click(function () {
- modaldia.dialog('open');
- modaldia.load("/home/testAjaxLoad", function () {
- $("#EffectiveStartDate").datepicker();
- });
- });
- });
- </script>
you comment is about "Never unbinding or re-calling .datapicker() ." you can call .datapicker() as much as you want on the same selector since all the ui controls use the widget factory so that you can extend them. the factory stores the instance of the jquery object in the $(selector).data("ui.datapicker") or what ever control (names space) your using. you can't have more then one instance of a date picker per html element because of this. all it does if you you call .datapicker() again and its all ready init then you get the current instance for that selector.
plus the actual date picker obj is a singleton thus there is only one.
here is code for the date picker from the jquery-ui.js that is called. even if you call .datapicker(option, value, get ). or any of the other calls that are in the api for after the control is initialization.
because the factory must first see if the control instance exist before it can chain the option calls
- $.fn.datepicker = function(options){
- /* Verify an empty collection wasn't passed - Fixes #6976 */
- if ( !this.length ) {
- return this;
- }
- /* Initialise the date picker. */
- if (!$.datepicker.initialized) {
- $(document).mousedown($.datepicker._checkExternalClick);
- $.datepicker.initialized = true;
- }
- /* Append datepicker main container to body if not exist. */
- if ($("#"+$.datepicker._mainDivId).length === 0) {
- $("body").append($.datepicker.dpDiv);
- }
- var otherArgs = Array.prototype.slice.call(arguments, 1);
- if (typeof options === "string" && (options === "isDisabled" || options === "getDate" || options === "widget")) {
- return $.datepicker["_" + options + "Datepicker"].
- apply($.datepicker, [this[0]].concat(otherArgs));
- }
- if (options === "option" && arguments.length === 2 && typeof arguments[1] === "string") {
- return $.datepicker["_" + options + "Datepicker"].
- apply($.datepicker, [this[0]].concat(otherArgs));
- }
- return this.each(function() {
- typeof options === "string" ?
- $.datepicker["_" + options + "Datepicker"].
- apply($.datepicker, [this].concat(otherArgs)) :
- $.datepicker._attachDatepicker(this, options);
- });
- };
- $.datepicker = new Datepicker(); // singleton instance
- $.datepicker.initialized = false;
- $.datepicker.uuid = new Date().getTime();
- $.datepicker.version = "1.10.2";
you may want to read this about the widget factory.