Knockout From and To datepicker scenario

Go To


I have a scenario where I use datetimepicker for inputting From and To dates. If I put a constraint in such a way that the "To" dates cannot be lesser than the "From" date, the bindings do not work anymore. Here is the fiddle:

Any ideas?

2012-04-03 23:49
by alpinescrambler


Datepicker will not fire change event in case you supplied onselect. Below is the piece from jquery ui code:

var onSelect = this._get(inst, 'onSelect');
if (onSelect)
  onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);  // trigger custom callback
else if (inst.input)
   inst.input.trigger('change'); // fire the change event

To solve you problem, update model in both onSelect (this will fire when user selected date from datepicker window) and 'onchange' (last one you still need to handle textbox editing


2012-04-04 02:47
by Artem
Thanks! I also found a work around using knockout's subscribe feature. This is the fiddle: - alpinescrambler 2012-04-04 14:59
for subscription I would better move this to bindingHandler - - Artem 2012-04-04 15:50
Very elegant @Arte - alpinescrambler 2012-04-04 20:51