JohnLouderback / GDB

Generic Data Binder (GDB) for jQuery is a framework agnostic and extremely easy to use 2 way data binder. GDB binds views and models in realtime with live two-way binding and no hefty framework necessary.
http://gdb.thewebdev.guru/
Apache License 2.0
87 stars 11 forks source link

Firefox bug with contenteditable element #6

Closed JohnLouderback closed 10 years ago

JohnLouderback commented 10 years ago

In Firefox, when altering a contenteditable element, the caret moves back to the beginning of the text.

The reason is because when the view updates the model, the model, in turn, updates the view. This behavior is unwanted and this causes the view to update while the user is typing and thus resetting the caret in Firefox.

Possible solution is adding a "tag" of sorts to the view data when inserting into the model and removing the tag when the model has sensed that it has been altered. If the tag is detected, the new information will not be added to the view and the tag will removed.

Potential problems can arise if the tag is not unique enough that it be genuine user input. Proposed tag: gdb-do-not-insert-into-view-gdb:

JohnLouderback commented 10 years ago

Used a much more simple solution. Had the function monitoring changes to the model check to see if the bound element's value did not already match the model and skip the view updating step if it did.