arturadib / agility

Javascript MVC for the "write less, do more" programmer
http://agilityjs.com
MIT License
542 stars 70 forks source link

Set/Get out of order for keydown event #31

Closed individual11 closed 13 years ago

individual11 commented 13 years ago

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 commented 13 years ago

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 reply@reply.github.com 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: https://github.com/arturadib/agility/issues/31

individual11 commented 13 years ago

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 commented 13 years ago

No problem, good luck!