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

Set/Get out of order for keydown event #31

Closed
individual11 opened this issue Jul 27, 2011 · 3 comments
Closed

Set/Get out of order for keydown event #31

individual11 opened this issue Jul 27, 2011 · 3 comments

Comments

@individual11
Copy link

Maybe I'm doing it wrong, but some events fire before set is fired and some fire after.

var ist = $$({}, '<div><input type="text" data-bind="newContent" /><ul></ul></div>', {
          'keydown input': function(e){
            if (e.keyCode != 13) return; //if any key other than enter hit

                        //will return undefined
              console.log( this.model.get('newContent') );
          },
          'change':function(e){
                        //will return the value of the input
            console.log( this.model.get('newContent') );
          }
        });

And the problem with using change as the event is that it fires when the input loses focus if the value is different.

@arturadib
Copy link
Owner

I'm not sure if DOM events should be fired after model events. Perhaps
in most uses people want to capture the event prior to any other
Agility event.

Have you tried the input type search? It updates the model upon
every keystroke, so you can just monitor the event change.

On Jul 27, 2011, at 6:21 AM, individual11
[email protected]
wrote:

Maybe I'm doing it wrong, but some events fire before set is fired and some fire after.

var ist = $$({}, '<div><input type="text" data-bind="newContent" /><ul></ul></div>', {
         'keydown input': function(e){
             if (e.keyCode != 13) return; //if any key other than enter hit

                       //will return undefined
             console.log( this.model.get('newContent') );
         }
         'change':function(e){
                       //will return the value of the input
             console.log( this.model.get('newContent') );
         }
       });

And the problem with using change as the event is that it fires when the input loses focus of the value is different.

Reply to this email directly or view it on GitHub:
#31

@individual11
Copy link
Author

I will give that a try. I guess I could also force the model to change manually in the event. Now I'm thinking a bit more about the logic, I see why change is firing after keydown .

Thanks much, you can close the issue if you want since you're right, I just wasn't thinking about it logically.

@arturadib
Copy link
Owner

No problem, good luck!

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

2 participants