Knockout-jQueryUI

Fork me on GitHub

Datepicker.html

Select a date from a popup or inline calendar

Parameters

For each of the widget's options the binding has a corresponding option with the same name. These can be set to static values, or bound either to normal or to observable properties of the viewmodel.

For each of the widget's events the binding has a corresponding option with the same name. These can be set to functions. When invoked the value of the this keyword evaluates to the viewmodel.

refreshOn

Should be bound to one of the viewmodel's observables. Every time that observable changes, the widget is refreshed (it's refresh method is invoked).

widget

Should be bound to one of the viewmodel's writeable observables. The binding will write a jQuery object containing the binding's DOM element into it. The primary use for this option is to invoke the widget's methods on the element.

value [two-way binding]

The selected Date. Note the difference between this option and knockout's built-in value binding, the examples below use both.

Example

HTML

<p>
  <span>Popup calendar: </span><br/>
  <input type="text" data-bind="datepicker: {}, value: valueString1" />
</p>
<p>
  <span>Inline calendar: </span>
  <div data-bind="datepicker: { value: value2 }"></div>
</p>
<p>
  <button data-bind="button: {}, click: to01012000">Set to 01/01/2000</button>
</p>

JavaScript

var ViewModel = function () {
  this.valueString1 = ko.observable();
  this.value2 = ko.observable();
};

ViewModel.prototype.to01012000 = function() {
  this.valueString1('01/01/2000');
  this.value2(new Date(2000, 0, 1));
};

Result

Popup calendar:

Inline calendar: