remy / bind.js

bind.js - simple two way data binding to HTML and callbacks
694 stars 62 forks source link

Support for programmatically modified values? #11

Open twanlass opened 9 years ago

twanlass commented 9 years ago

For example, why doesn't this work? https://jsfiddle.net/k25zfbm7/

remy commented 9 years ago

Not sure I follow - the subject suggests there's a problem with input[type=hidden], but there isn't one...

twanlass commented 9 years ago

@remy my apologies - fixed the title, forgot to save.

Re: the jsfiddle above - wondering what I'm doing wrong or if this functionality is not implemented. I've got a few places where the input values are modified via jQuery et el but not seeing the binding update (no callback fired when changed etc).

Cheers!

-t

AVGP commented 9 years ago

I see a use case for that, when bind.js is used in a larger application, but you could still set the value programmatically in your example:

Instead of $('.name').val('tyler'); you use names.name = 'tyler'; instead.

remy commented 9 years ago

Oh, I think I follow now. Are you expecting the bound object to update when you change the input using jQuery?

If that's the case, I'm pretty sure you want to trigger a change event on the input element, since that's how bind.js is picking up the change.

$('input.name').val('tyler').trigger('change');
remy commented 9 years ago

@twanlass did that work?

twanlass commented 9 years ago

@remy - calling trigger('change') doesn't appear to, no.

adelriosantiago commented 7 years ago

trigger('change') doesn't do the trick, any ideas?