0

I have a custom Binding that works on Keyup and when users manually type in data the valueAccessor().call works just fine and enters the desired next function. However, when we barcode the same data, and send the same return key, (i have checked that the last keyCode being send is 13 with both methods) the valueAccessor doesn't make it to the next function and drops out.

I suspect this could have something to do with the speed at which the barcoded data is entered into the field and the subsequent "enter" key. Would slowing down the rate the barcoded characters are entered help? If so, what method do you suggest?

ko.bindingHandlers.enterKey = {
init: function (element, valueAccessor, allBindings, vm) {
    ko.utils.registerEventHandler(element, "keyup", function (event)
    {
        if (event.keyCode === 13)  {
            ko.utils.triggerEvent(element, "change");
            valueAccessor().call(vm, vm); 

        }

        return true;
     }
    );
}
andy
  • 485
  • 1
  • 7
  • 16
  • Are you sure it is being fired at all? On key up doesn't seem like it would catch a programmatic event the same way but I may be wrong... – PW Kad Oct 23 '14 at 19:19
  • I am pretty certain it is. I placed a break-point below the if statement in Chrome and it stops there. I am evaluating the Keycode there and it is set to 13. I could be misinterpreting what I am seeing though. – andy Oct 23 '14 at 19:27
  • I don't understand what you mean by "the valueAccessor doesn't make it to the next function and drops out". Could you explain? – Michael Best Oct 23 '14 at 23:24
  • Sure, when data is typed via keyboard into the field and users hit enter I have observed keyCode = 13 then the code steps into the Triggerevent then valueAccess().call is called which then calls another function called Scan, which is the expected behavior. However, when the same data is scanned with a barcode reader, the keyCode evaluates as 13 as before, the triggerEvent is called and the code steps to the valueAccess().call, but Scan isn't called next as was the case when the data was typed in with the keyboard. I have compared vm during both methods, and the are identical – andy Oct 24 '14 at 00:12
  • As a side note, using the built in [`event` binding](http://knockoutjs.com/documentation/event-binding.html) is way more suitable than a custom binding handler IMO, at least as far as code shown. You just do `event: { keyup: myCallback }`, and return true from `myCallback` if you need it to bubble. – Jeroen Oct 24 '14 at 07:04
  • Setting barcode up programmatically on load does not also trigger a buggy behaviour. Could you post the code of the vm, especially for the property that you have bound it to with your custom binding ( I am guessing its another ko observable or a function)..thanks – ajeeshpu Oct 29 '14 at 09:22

1 Answers1

0

thanks for the help on this. It turns out there was a misnamed variable in the VM.

andy
  • 485
  • 1
  • 7
  • 16