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

submit event for forms does not fire #64

Closed
docyes opened this issue Dec 17, 2011 · 2 comments
Closed

submit event for forms does not fire #64

docyes opened this issue Dec 17, 2011 · 2 comments

Comments

@docyes
Copy link

docyes commented Dec 17, 2011

I can't seem to setup an event listener for the submit event on a form. See example below...

var searchbar = $$({
model:{},
view:{
format:
'




',
style:
'& input[type="search"] {width:70%;}
& input[type="submit"] {width: 10%;}'
},
controller:{
'submit form': function(){
alert(16);
}
}
});
$$.document.append(searchbar);

@arturadib
Copy link
Owner

At the moment Agility won't include the root element of a view in the event selector (this behavior can be traced back to jQuery), so the controller submit form doesn't pick up any element.

To get around it, you can either explicitly select the root element with submit & (see http://agilityjs.com/docs/docs.html#events-dom), or create a dummy root element for your view so that the form selector is picked up by jQuery:

var searchbar = $$({
   model:{},
   view:{
       format:
           '<div>\
             <form> \
               <input type="search"> \
               <input type="submit" value="search"> \
             </form> \
           </div>',
       style:
           '& input[type="search"] {width:70%;} \
            & input[type="submit"] {width: 10%;}'
   },
   controller:{
       'submit form': function(){
           alert(16);
       }
   }
});
$$.document.append(searchbar);

@docyes
Copy link
Author

docyes commented Dec 17, 2011

Thanks, totally reasonable!

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