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
4133
Incorrect value in igDateEditor, valueChanged event firing when value is unchanged
posted

I was working with an igDateEditor() and was getting valueChanged() events firing at incorrect times, such as when a user focused and blurred the date editor control, but never changed the value.  I found out that there was a difference in value when getting the igDateEditor("value") at different times.

If you set the value of igDateEditor to a Date object, then query the value, you get the original Date object value you set it to, but if you focus and blur the igDateEditor then query the value, you get a value that is then formatted according to the igDateEditor option "dateInputFormat".  If dateInputFormat is "date", the value of igDateEditor("value") is stripped of the time, even when the user never changed the value, but simply focused and unfocused the control.

I have included a code sample below:

    function log(message) {
        alert(message);
    }
    $(function () {
 
        var dp = $("#datePicker");
        var initDate = new Date(1423779102730-0500); //2015-02-12 17:11:42
    
        dp.igDateEditor({
            dataMode: 'date',
            dateDisplayFormat: 'date',
            dateInputFormat: 'date'
        });
    
        // if control is untouched by the user, we get the full-formatted, original value back
        dp.igDateEditor("value", initDate);
        log(dp.igDateEditor("value"));
    
        // until the user focuses and unfocuses the control, then the
        // value is formatted depending on the dateInputFormat
        dp.focus();
        dp.blur();
        log(dp.igDateEditor("value"));
 
    });

This gives us two different values, though the value was never manually changed:

Thu Feb 12 2015 17:11:42 GMT-0500 (Eastern Standard Time)
Thu Feb 12 2015 00:00:00 GMT-0500 (Eastern Standard Time)

Can you verify this is the intended functionality?  This scenario is kind of odd, and I've had to essentially wrap some of the Ignite UI functions and implement value formatting myself to avoid the valueChanged() event.

Thanks.