ember.js - Figure out which button[type=submit] was clicked in a multi button form -


with ember.js, following case:

<form {{action 'save' on="submit"}}>   <button type="submit" data-source='x'>do x</button>   <button type="submit" data-source='y'>do y</button> </form> 

inside save() event, how 1 figure out button clicked?

(i need form way is, , need button[type=submit] too. know can 2 actions on buttons, fire form native submit, if way have 2 separate actions, i'll disappointedly manually fire form submit on each, there has easier way)

the action helper not pass jquery event information, can access using view's event handler instead. example define submit-event handler like:

app.multibuttonform = ember.view.extend({   tagname: 'form',   submit: function(event) {     console.log('submit with: ', event);     event.preventdefault();   } });  {{#view app.multibuttonform}}   <button type="submit" data-source='x'>do x</button>   <button type="submit" data-source='y'>do y</button> {{/view}} 

see https://github.com/emberjs/ember.js/issues/1684 discussion of action helper vs. view event handler

also see post ideas on how figure out button pressed: http://www.webmuse.co.uk/blog/using-forms-with-multiple-submit-buttons-and-jquery-events/


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -