-
Notifications
You must be signed in to change notification settings - Fork 310
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
Default "rv-value" should also listen to inputs "change" event #610
Comments
Hi Superware, This is the perfect scenario for a custom binder. Something like I don't have the time to shoe-horn a typeahead implementation into jsfiddle. But here is what your binder will look like: rivets.binders.typeahead = {
bind : function(el) {
$(el).typeahead({
minLength: 3,
highlight: true
},
{
name: 'my-dataset',
source: mySource
})
.on('typeahead:selected', function(event, selection) {
this.observer.setValue(selection); // not sure if you need to get a value from the selection.
}.bind(this));
},
unbind : function(el) {
$(el).typeahead('destroy');
},
routine : function(el, value) {
$(el).typeahead('val', val);
}
} Let me know if this helps. If this resolves your problem, please close this issue. |
Hi Duder, Please see this jsfiddle, it seems bootstrap-typeahead is triggering a "change" event upon item selection, but rivets default rv-value doesn't respond to "change" events. If it's not possible to react to "change" events, then one must re-implement rv-value as rv-whatever to get this functionality (registering to key-events, paste/cut etc). Am I right? Thanks! |
Hi Superware, But hey! It looks like that binder worked for you! This is why rivets is so damn cool (IMO). You can do it however you think makes the most sense. Another way to do it would be to write a binder using the Typeahead fires a change event when the user selects something. You can listen for that and just set the model directly. Here is a working fiddle demonstrating that: https://jsfiddle.net/Vornagreg/yej2scu8/1/ This would look something like: <input rv-on-change='callMethodOnModelThatSetsValue'/> var _model = {
state: "",
applyValueToModel : function(event, context) {
this.state = event.target.value;
}
};
// THis will ensure that methods are called with the _model as scope.
rivets.configure({
handler : function(context, ev, binding) {
// https://github.com/mikeric/rivets/pull/275#issuecomment-36464555
this.call(binding.observer.target, ev, binding.view.models);
}
});
rivets.bind($("#container"), _model); |
But Thanks again. |
You are correct again. It is also useful to keep it as a 'input' event because you might want to do some kind of input masking and you would like that masking to happen as the user is typing. In any event, if it makes more sense to you for the |
I guess Plus, I've seen/used the pattern |
I'm using typeahead like this:
<input rv-value="service.name" data-provide="typeahead" />
When selecting an item typeahead sets the input value and triggers a "typeahead:selected" event, can rivets react to that event and update the model?
Thanks.
The text was updated successfully, but these errors were encountered: