BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
856 stars 130 forks source link

$(...).trigger('change') will not update data-linked value after commit 84 #381

Closed shimooka closed 7 years ago

shimooka commented 7 years ago

Hi.

Is there any solution ?

-=-=-=-=-=-=-

I try to use EmojiOneArea (https://github.com/mervick/emojionearea) with jsviews, and EmojiOneArea seems like use trigger() when updateing a input tag .

BorisMoore commented 7 years ago

Yes, that is deliberate. If you use the default trigger=true setting, then updates happen after each keyDown event. But then you don't want an additional update to happen on the blur/change event. So the trigger() or change() action is skipped. (Prior to commit 84 the change handler was getting called twice - once after keyDown once on blur/change.)

If you want to be able to enable using trigger() - so EmojiOneArea works, you can disable the async trigger. Either set $.views.settings.trigger(false) globally, or on the specific input:

<input type="text" id="label" data-link="label trigger=false"/>

Now updating will only happen on blur, but trigger() will work.

UPDATE: If that does not suffice for your needs, you can use trigger='change keyup' - see comment below...

shimooka commented 7 years ago

Hi Boris !

I will try to use 'trigger=false' . thanks for your reply :-)

BorisMoore commented 7 years ago

Oh - by the way, another option is to write

<input type="text" id="label" data-link="label trigger='change keyup'"/>

or $.views.settings.trigger("change keyup");

With that setting and trigger/blur/change will work as well as updating on keyup (which is a slightly less good as a user experience than the async keydown you get when trigger is set to true, but may still be a good experience for your needs...)