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

input[type=number] on(change) not executing publish event #381

Closed
ashishtilara opened this issue Sep 23, 2014 · 3 comments
Closed

input[type=number] on(change) not executing publish event #381

ashishtilara opened this issue Sep 23, 2014 · 3 comments

Comments

@ashishtilara
Copy link

I have a input[type=number], and when I type non-numeric number it doesn't cause change event for some reason and so the publish doesn't get called either, is there any way to get around this.

I have this JSFiddle[http://jsfiddle.net/itcutives/mavu1jar/4/] but i am not sure if what I have is correct, but adapter events not printing anything in console so I think they are not even executing.

@Duder-onomy
Copy link
Collaborator

As you can see in this fiddle, that is a problem with the input type='number' and not rivets.
http://jsfiddle.net/c9c733g3/

Also, your adapter needs to overwrite the build in dot adapter. The rivets website recommends a : adapter for backbone models: http://rivetsjs.com/docs/guide/#adapters-creating

I changed your adapter appropriately.
The important thing to note about this : adapter is that you should only use it to access model properties, model methods should be accessed with the build in dot adapter.

I also moved your backbone model properties into the defaults option, and model methods to the root of the extend.

A couple ways to get around this issue with the input:

  1. Use the rv-on-input to solve this, though you should probably use a custom handler:
    notice that I added a handler function to your rivets.configure. Checkout out this github issue to see how that works. Check out this Fiddle to see it working with the model change, the adapter change, and the handler on the input event. http://jsfiddle.net/mavu1jar/9/
  2. Override that specific input's input event and fire change on it manually.
    Here is a working fiddle: http://jsfiddle.net/mavu1jar/11/
$('input').on('keypress paste textInput input', function () {
    $(this).trigger('change');
});

@ashishtilara
Copy link
Author

Thank you @Duder-onomy 👍

@AWinterman
Copy link
Contributor

If that solution works, this issue should be closed!

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

3 participants