I can't see a igDatePicker specific forum so I hope this is the right place for a query on it.
igniteUI 13.1, MVC5, jquery-1.7.1, jQuery ui 1.8.20
I am using two igDatePickers in my view to capture Start date and an end date for some processing.
Here is the Razor that defines them:
<div class="float-left-box"> <h2>Refresh invoice dates from Xeroh2> <div class="float-left-clear-left"> @Html.LabelFor(m => m.InvoiceDateRefreshStartDate, "Start date") @Html.Infragistics().DatePickerFor(m => m.InvoiceDateRefreshStartDate).ID("dpIDRStartDate").DateDisplayFormat(Model.DateFormat).DateInputFormat(Model.DateFormat).InputName("InvoiceDateRefreshStartDate").Width(120).Render() @Html.Infragistics().DatePicker().ID("dpIDRStartDate2").DateDisplayFormat(Model.DateFormat).DateInputFormat(Model.DateFormat).InputName("InvoiceDateRefreshStartDate2").Width(120).Render() div> <div class="float-left-clear-left"> @Html.LabelFor(m => m.InvoiceDateRefreshEndDate, "End date") @Html.Infragistics().DatePickerFor(m => m.InvoiceDateRefreshEndDate).ID("dpIDREndDate").DateDisplayFormat(Model.DateFormat).DateInputFormat(Model.DateFormat).InputName("InvoiceDateRefreshEndDate").Width(120).Render() div> <input type="button" id="btnUpdateInvoiceDates" value="Update invoice dates"/> div>
When the button is clicked I want to use ajax to call a method in my controller, so I have this jQuery:
<script type="text/javascript" > $(document).ready(function () { $("#btnUpdateInvoiceDates").bind({ click: function (e) { $.ajax({ type: "GET", url: "/@XeroSettingsController.ControllerName/@XeroSettingsController.ACTION_UpdateInvoiceDates", data: { InvoiceDateRefreshStartDate: $("#dpIDRStartDate").igDatePicker("option", "value"), InvoiceDateRefreshEndDate: $("#dpIDREndDate").igDatePicker("option", "value") }, contentType: "application/json; charset=utf-8", dataType: "json", success: successFunc, error: errorFunc }); } }); function successFunc(data, status) { alert(data); } function errorFunc(a,b,c,d) { alert('error'); } }); script>
When the Ajax call is made (or at least, attempted) I get the following error:
Error: cannot call methods on igDatePicker prior to initialization; attempted to call method 'option'
If I debug in Firefox a watch on this expression produces the same error:
$("#dpIDRStartDate").igDatePicker("option", "value")
So this is now driving me bonkers. How to I get the igDatePicker to initialise itself such that I can actually use it?
I am using it with success elsewhere in my site, but as part of a form. The difference here is that I am not using the igDatePickers in an html form.
I can change the dates quite happily on the web page but I still run into this error, so the igDatePicker is up and running, just not initialized.
Regards,
Graeme
I have replaced $("#dpIDRStartDate").igDatePicker("option", "value") with $("#dpIDRStartDate").igEditor("option", "value") and now get the following error from infragistics.core.js when I click my button:
TypeError: this.getFullYear is not a function
RTFM, namely :
http://www.igniteui.com/date-picker/hotel-reservation
Which has an MVC example of using a igDatePicker.
So, I am getting further but have replaced one obscure error message with another.
...this is where I got my original attempt at getting the value of the igDatePicker, so there seems to be some confusion in the docs:
http://help.infragistics.com/jQuery/2013.1/ui.igdatepicker
The Options tab has an entry for the value option, which gives an example which caused my original error.
In one place it says use igDatePicker, in another it says use igEditor, and the latter worked for me.
Finally figured it out.
Convert the date picker value to a string for the Ajax call, then it works OK:
var requestData = { InvoiceDateRefreshStartDate: $("#dpIDRStartDate").igEditor("option", "value").toJSON().substring(0, 10), InvoiceDateRefreshEndDate: $("#dpIDREndDate").igEditor("option", "value").toJSON().substring(0, 10) }; $.ajax({ type: "POST", url: "/@XeroSettingsController.ControllerName/@XeroSettingsController.ACTION_UpdateInvoiceDates", data: JSON.stringify(requestData), contentType: "application/json; charset=utf-8", dataType: "json", success: successFunc, error: errorFunc });
Oh, and the controller method needs to take the dates as string parameters then use DateTime.trycast to convert them to dates.
If the parameters are DateTime it throws more errors.