gvas / knockout-jqueryui

Knockout bindings for the jQuery UI widgets.
http://gvas.github.com/knockout-jqueryui/
MIT License
103 stars 38 forks source link

Datepicker - Set Date #7

Closed Vik-- closed 11 years ago

Vik-- commented 11 years ago

Hi,

I am using knockout-jqueryui in my SPA application (Hot Towel template). I am able to use the knockout-jqueryui datetime picker on my view, but need help in getting the following:

  1. Set the date value.
  2. Provide mask characters for users to type in the date in the input text box.
        <input type="text" data-bind="datepicker: {
                                        onSelect: onDOBSelect,
                                        maxDate: maxDate,
                                        defaultDate: defaultDate,
                                        buttonImage: calendarImageUrl,
                                        buttonImageOnly: true,
                                        showOn: 'both',
                                        dateFormat: 'mm/dd/yy'}" />  

The viewmodel has the variables defined thats used in the datepicker.

Thanks in advance.

Vik

gvas commented 11 years ago

Hello,

  1. you can use knockout's value binding to update the input's value. Or you can add an observable property named 'widget' to your viewmodel, knockout-jqueryui will write the datepicker instance into it. After that you can use the datepicker's setDate() method.
  2. you should write a custom binding handler to apply the mask.

Here's a jsfiddle: http://jsfiddle.net/GRPV2/2/

Regards, G

Vik-- commented 11 years ago

Perfect!! Thanks a ton.