Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contenteditable is not 2-way-bound #356

Open
pYr0x opened this issue Nov 17, 2017 · 6 comments
Open

contenteditable is not 2-way-bound #356

pYr0x opened this issue Nov 17, 2017 · 6 comments

Comments

@pYr0x
Copy link

pYr0x commented Nov 17, 2017

this example shows two each loops.
first one with a contenteditable div
second one with a standard inputfield
http://jsbin.com/zuxececoce/1/edit?js,console,output

the first editable div is not working, while the standard input field is working live expected
cc @phillipskevin

@chasenlehara
Copy link
Member

Here’s a slightly more simple example that doesn’t use a DefineList or #each: https://jsbin.com/wihobujere/1/edit?js,console,output

@bmomberger-bitovi
Copy link
Contributor

After some discussion on the Gitter channel we've discovered that the presence of jQuery in the example JSBins is the thing causing this breakage. When jQuery is removed, the correct 2-way binding behavior happens.

Why jQuery causes this, is as yet unknown

@pYr0x
Copy link
Author

pYr0x commented Nov 19, 2017

really strange...
i dont know how canjs today implemented the change event on a contenteditable div.
but it seems, that the input-event is also fired for contenteditable elements.
see: https://developer.mozilla.org/en-US/docs/Web/Events/input
maybe we have to implement a sepical case for contenteditable elements

@pYr0x
Copy link
Author

pYr0x commented Nov 19, 2017

maybe this is the right solution.
https://jsbin.com/cowucix/1/edit?js,console,output
not to use the innerHTML change event. instead use the blur event.

here are some examples:
https://jsbin.com/giyexun/1/edit?js,console,output -> with contenteditable and the blur event. this is the same behaviour like an input element
https://jsbin.com/pugitow/1/edit?js,console,output -> standard input value binding.

typeahead:
https://jsbin.com/yehonud/1/edit?js,console,output -> if you want a input-element and a typeahead behaviour then this is pretty standard with canjs.
https://jsbin.com/gozoxof/1/edit?js,console,output -> typeahead with contenteditable is not that easy like the input example.

@phillipskevin is there a way to add some syntactic suger for the cotentedtiable element. or is the better way to create a custom element with that logic (e.g. typeahead with range-selection)

@pYr0x pYr0x closed this as completed Nov 19, 2017
@pYr0x pYr0x reopened this Nov 19, 2017
@phillipskevin
Copy link
Contributor

@pYr0x I can't quite remember what we talked about, but for this example:

<div contenteditable="true" on:blur="change(~this.name, scope.element)">

did you not want to use this instead?

<div contenteditable="true" on:blur:innerHTML:to="name">

@bmomberger-bitovi
Copy link
Contributor

Did something change around the on:...:to syntax recently? Last I understood it, on:event:X:to only works for X =value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants