This is a migrated thread and some comments may be shown as answers.

MVVM Binding

2 Answers 11 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 03 Apr 2014, 05:38 AM

I have a date field:

     <input name="myDate" type="date" data-bind="value: myDate, click: getDate" />

I'm doing this because the version of Android webkit doesn't have a datepicker and acts like a text field. The getDate function opens a dialog box to capture the date and updates the date field to simulate user input:

     $(currentField).val(yyyy+"-"+mm+"-"+dd);

The new date value is reflected onscreen on the page.

However, the new date value doesn't reflect on the view model.

Any ideas why? Is there a binding conflict? How do I avoid it?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 03 Apr 2014, 08:42 AM
Hi Jay,

In order to update both the input and ViewModel you should change the value in the ViewModel through the set method. For example:
viewModel.set("myDate", yyyy+"-"+mm+"-"+dd);

An alternative approach is to set the input value and manually triggers its change/input event in order to force the MVVM to update the ViewModel.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jay
Top achievements
Rank 1
answered on 03 Apr 2014, 12:05 PM
Thanks. I triggered the change event via $(currentField).change() and that worked like a charm!
Tags
General Discussions
Asked by
Jay
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Jay
Top achievements
Rank 1
Share this question
or