Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
160
igDateEditor value method problem
posted

I cannot figure out how to get the actual Date value from an igDateEditor. I have tried using the value method but I don’t know if I am using it correctly. I use the following and was expecting a Date value.

 

var toDateVal = $("#dtpFrom").igDateEditor("value");

 

Instead of a Date value, toDateValue is b.fn.b.init[1] where the value at 0 index is the HTMLSpanElement that is generated by the MVC code.

 

I setup the DateEditor in the MVC view, like this:

                <div class="editor-label">

                    @Html.Label("From")

                    <div style="float: right;">

                        @(Html.Infragistics().DatePickerFor(m => m.DateFrom)

                            .ID("dtpFrom")

                            .Width(120)

                            .DateInputFormat("d/M/yyyy")

                            .DataMode(DateTimeEditorDataMode.Date)

                            .Value(filterFrom)

                            .Render()

                        )

                    </div>

                </div>

 

Which renders as:

<div class="editor-label">

     <label for="From">From</label>

     <div style="float: right;">

           <span id="dtpFrom"></span><input name="DateFrom" type="hidden"></input><script type="text/javascript">//<!--<![CDATA[

$.ig.loader('igEditors', function() {$('#dtpFrom').igEditor({ type: 3, button: 'dropdown', dataMode: 'date', inputName: 'DateFrom', value: new Date(2012, 6, 25, 0, 0, 0, 0), width: 120, dateInputFormat: 'd/M/yyyy' });});

//]]>--></script><script type='text/javascript'>$(document).ready(function() { if ($.ig.TrialWatermark === undefined) { $('<div></div>').appendTo(document.body).css({width: $(document.body).width(), height: $(document.body).height(), position:'absolute', top: 0, left: 0, zIndex: -1}).addClass('ui-igtrialwatermark'); $.ig.TrialWatermark = true; } });</script>

     </div>

</div>

 

I am using 12.1 (3.12.1.2023) on Infragistics.Web.Mvc.

Thanks,

 

Simon

  • 160
    posted in reply to [Infragistics] Viktor Snezhko

    Thanks for the reply.

    I had been looking at the igDateEditor help which showed the igDateEditor option present so I had assumed that the date picker object would always have igDateEditor. A subtle difference that I will keep a look out for. Are there other cases where the MVC generated JS objects may not match the client-side written code?

  • 24497
    Verified Answer
    posted

    Hi Simon,

    All Mvc editors use the igEditor, but not igDatePicker, igMaskEditor, etc. Actually part of generated html, which you pasted show that as well.

    That means that if you want to access existing widget, then name should be exactly the same as name used to create a widget. Otherwise, jquery might automatically generate another widget and attach it to target. In case of wrong name, besides wrong "output", that will probably destroy functionality of editor: events can be doubled, etc.

    Please use something like,

    var toDateVal = $("#dtpFrom").igEditor("value");

    $("#dtpFrom").igEditor("value", new Date(2012, 8, 5));

    $("#dtpFrom").igEditor("option", "dateInputFormat", "yyyy-MM-dd h:mm:ss ttt");

    $("#dtpFrom").igEditor("option", "am", "A");

    etc.