Create an array from a form


#1

Hello everyone. I wonder how I do to assemble an array of a form? Example, have a ‘emails’ field and want to add 3 emails to that field. How to do it in the template? valueBinding=“emails[]” ?


#2

I’d have the email addresses separated with , (or whitespace) in the input field and bound to a property of the controller. Something like:

{{input type="text" value=emails placeholder="Enter emails separated by ," action="sendInvitations"}}

Then in the controller (or route) I would handle the action:

actions: {
  sendInvitations: function() {
     var emails = this.get('emails').split(',');
     // do whatever is needed with each email, now an array of email addresses
  }
}

#4

@balint thanks man, but don’t work for me. I used pushObjects and works fine. :wink:


#5

@paulohp Could you post the code snipped where you used pushObject and the template usage?