Wednesday, 15 February 2012

javascript - emberjs get all form fields / values at once -


When creating new form fields in ember.js, it seems as if there is a multi-step process, for example, I create the form field: {{Input value = email type = "email" placeholder = "email" required = "required"}} {{input value = password type = "password" Placeholder = "password" required = "required"}}

Then in my controller I have this:

  App.AccountController = Ember ObjectController Extend ({e El: empty Password: empty, actions: {log: function} {var data = this.getProperties ( "email", "password"); console.log (data);}}});  

As you can see, the email and password are defined as tap on the top, and then in the data version the user will be able to get 'value' in the fields again. Is defined by.

Is there a way around this, where I can just say ... Assign all the values ​​of the form, to empty, and then get all the form field values ​​in a row? Is it possible to serialize the form in jQuery?

Avoid duplication, but at a price which is not worth it.

First of all, you do not have to define fields in your area. Controller These two lines can be completely deleted:

  email: empty, password: blank,  

However, I keep them for documentation purposes Recommend (although they are unnecessary.)

Secondly, you should realize that Amber does not have any concept of 'form'. You have not specified any form, only two input boxes if you want, what you really want to do, but you only suggest that if you were creating the lot form Finally, you are going to have a fair amount of repetition.

It's being said, I think your code is correct as you wrote it. Do not see the shortest way to write code; Find the most readable way to write code. You currently have the code that is the most readable version of that code (in my opinion).


EDIT: I did not notice that ObjectController was being used. Receive and set the call for the contents of the controller further if the fields are not explicitly set on the controller. This means that it will not work to remove those two lines, however, if you grow by controller instead of the object controller (which is deprecated anyway), it will work .


No comments:

Post a Comment