Is this a bug in the value-binding?

39 views
Skip to first unread message

Andreas Hoffmann

unread,
Jan 10, 2017, 6:05:47 AM1/10/17
to KnockoutJS
Hi,

I am not sure if this can regarded as a bug. It depends a bit on your mission-statement...

Steps to reproduce:
- Create an input-field with a standard value-binding.
- Create a button with a click-binding.
- Drag and drop a text from another window into the text-field.
- Click the button

Result:
The text dropped to the input-field is NOT in the observable.
This happens at least in Chrome and Firefox on Windows 7.


Why does this happen?
The change-event does not fire.

Should this be fixed?
Strictly speaking, knockout handles all events, it is designed to. But this kind of defeats the purpose of having a value-binding in the first place.
I really depends on the way you see knockout. 
Is it just a fancy event-handler? Then don't fix it.
Is it a library to handle user-inputs in a consistent manner? It should probably be fixed.

I can think of two ways to fix this:
1.) Just patch the current value-binding by registering an additional event-listener (insert the code below line 4892 in version 3.4.1, that's what we did):
if (eventName === "change") {
ko.utils.registerEventHandler(element, "input", function () {
if (element !== document.activeElement) {
handler();
}
});
}

2.) Define a new valueUpdate-event (like "changeAndFocusLost") that fixes the weaknesses of the change-binding.

Regards
Andreas


Gunnar Liljas

unread,
Jan 10, 2017, 7:20:46 AM1/10/17
to knock...@googlegroups.com
Maybe it should be fixed, but it works just fine when using the "textInput" binding instead of "value".

/G 

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Hoffmann

unread,
Jan 10, 2017, 7:38:57 AM1/10/17
to KnockoutJS
Hi,

that does not work for us, since the results are validated as soon as the model updates. The textInput-binding updates the model on every keystroke. The error-icon would then appear on the first keystroke already in case of an incomplete input.

What we need is the event: the value property changed AND the element does not have the focus. That is exactly the purpose of the change-event. Looks a bit like a loophole in the spec: The event is expected to fire every time, the element's value changed and the user is "done". Thus the event is fired when the focus is lost and the value changed. But using Drag and Drop, the user can now edit the value without the element receiving the focus.

To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages