Knockout From and To datepicker scenario

Go To StackoverFlow.com

0

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: http://jsfiddle.net/ericpanorel/PkpP6/

Any ideas?

2012-04-03 23:49
by alpinescrambler


0

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

fiddle:

http://jsfiddle.net/PkpP6/1/

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