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
295
igDatePicker Knockout Binding Issue/Bug
posted

I'm working with IgniteUI for the first time and working on putting controls on my page, and using knockout for databinding.

I followed the example from the following page: (https://www.igniteui.com/editors/bind-editors-with-ko) Please put some text outside of the code to point out that the knockout bindings only work with the additional javscript resource to include the knockout extensions. I wasted a lot of time as I overlooked that reference in the code example. You could save another customer the frustration.

Using the developer tool in chrome, I found where the error was occurring. 

I structure my ViewModel like:

var Payment = function (data) {

    var self = this;
    self.Id = ko.observable();

    self.PaymentType = ko.observable();
    self.CheckAmount = ko.observable();
    self.PaymentDate = ko.observable();

    if (data != null)
        self.update(data);

}

then I create a new method for my Payment View Model to update the data:

Payment.prototype.update = function (data) {
    this.Id(data.Id);
    this.CheckAmount(data.CheckAmount);
    this.PaymentDate(dtformat(data.PaymentDate));

}

This allows me to set up my bindings early, and when the data is fetched, I just use the update method to fill the view model with data.

I databound a textbox control and it worked fine this way, but when I added an igDatePicker, I got an error in the ignite/knockout extension script:

http://cdn-na.infragistics.com/igniteui/2014.2/latest/js/extensions/infragistics.ui.editors.knockout-extensions.js

I think it occurs where value.toString() is called. Value is undefined at the point that the bindings are set up. It looks like that 'else' statement should only allow (value != undefined).  FWIW, I modified my view model constructor to initialize the observables to null and is an acceptable workaround. But I think you should fix this bug nonetheless.

if(value===null&&value!==undefined)
{
    editor.igDatePicker("value",value)
}
else
{
    value=value.toString().replace(/_(\d)/g,"$1");
    parsedDate=Date.parse(value);
    if(value.toString().indexOf("/Date(")===0)
    {....

I'd also like to point out since I'm just diving into these controls that I'm quite disappointed in the themes. The controls aren't consistent. I put a textbox, a combobox, and a datepicker all on the same screen and they are all different size control heights and font sizes.  It's cumbersome to get in there and figure out which css I need to override to normalize the font sizes across the controls. When you put them on a form together, they look terrible. 

I'm using the ios theme and I even noticed on your example theme page (https://www.igniteui.com/themes/ios) that you are overriding the font size on the div that contains the control which seems to help some, but like I said, it's disappointing that the default styles aren't consistent.