0

I have date control that looks like this.

<div class="OnTheMoveFormTextBoxContainer">
                       <input data-bind="value: formatDateTime(ko.unwrap(Started)), css: { validationElement: validateItem(Started, 'Started') }, event: {
change: function(d, e) {
    if (Started != $(e)[0].target.value &amp;&amp; dateWheelShown == true) {
        $data.Started(dateToISO($(e)[0].target.value,'DD/MM/YYYY HH:mm'));
    }
}
 }, id: 'Started' + '_' + Id()" data-onthemove_dateformat="DD/MM/YYYY HH:mm" class="Mobile_DateTimePick ui-input-text ui-body-c ui-corner-all ui-shadow-inset ui-mini" data-mini="true" name="Started" id="scoller1400844006695" readonly="">
</div>

How could I access data-bound event handlers in knockout.js, I this current case onchange.

I am looking for something like this: ko.contextFor($($('.OnTheMoveFormTextBoxContainer')[3]).find('input')[0]).events

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265

1 Answers1

1

You can use ko.bindingProvider.instance.getBindings.

Something like (untested):

 ko.bindingProvider.instance.getBindings(
              $($('.OnTheMoveFormTextBoxContainer')[3]).find('input').get(0),
              ko.contextFor($($('.OnTheMoveFormTextBoxContainer')[3]).find('input').get(0).$root
 ).event.change

Update Maybe more like: var x = $($('.OnTheMoveFormTextBoxContainer')[3]).find('input').get(0);

ko.bindingProvider.instance.getBindings(x, ko.contextFor(x)).event

See this thread Access knockout binding from child element

Community
  • 1
  • 1
GôTô
  • 7,974
  • 3
  • 32
  • 43