indexiatech / ember-forms

Smart, Intuitive forms for Ember.js styled with Bootstrap, Multi layouts and Validation support.
http://indexiatech.github.io/ember-forms
Apache License 2.0
218 stars 45 forks source link

Validation Suggestion #76

Open jackmatt2 opened 9 years ago

jackmatt2 commented 9 years ago

I propose that validations be passed into the form as an attribute and em-form include the EmberValidations.Mixin.

{{#em-form model=employee validations=myValidations}}
   ...
{{/em-form}}

<!-- another form on the same screen using the same DS.Model class with completely different validations -->
{{#em-form model=employee2 validations=myValidations2}}
   ...
{{/em-form}}

This would solve a number of issues:

  1. Generally, validations should not be specified on the model because different routes might require different validations for the same model.
  2. This approach would allow you to specify different validations for the same model class in the same route.
  3. Users can get started more easily as they don't need to download the dependency and apply the Mixin themselves.

The downside of the approach is that Ember-Validations would become a dependency on the project. I still believe however that most people would want some sort of client side form validations and that this is one of the strengths of ember-forms. If people did not care about validations it is almost as easy to write the code in native emberjs and applying the bootstrap classes thus bypassing emer-forms altogether.

asaf commented 9 years ago

@jackmatt2 Thanks, just one question though, as you mentioned in #72 , and as we always do, we put the validations on the controller level,

This solves point 1.

In what scenario you find the need to have different validation rules for the same controller? this sounds like a bad structure to me,

Regarding point 3, ember-validations is already a dependency of the ember-forms addon.

Thanks

jackmatt2 commented 9 years ago
@jackmatt2 Thanks, just one question though, as you mentioned in #72 , and as we always do, we put the validations on the controller level,

This seems to work for Em.ObjectController, however, it does not work for Em.Controller. As I understand it, Ember 2.0 is heading toward Em.Controller and scrapping Em.ObjectController completely so I would suggest support for it.

In what scenario you find the need to have different validation rules for the same controller? this sounds like a bad structure to me,

Say you had a form to create a new user and you were able to specify the type of user "regular" or "admin". Maybe a regular user can have a password length of 6 characters but an admin user needs 12 characters. The validations would need to change depending on what was selected in the drop down.

Regarding point 3, ember-validations is already a dependency of the ember-forms addon.

Oh, good. Forget my comment about that then.

asaf commented 9 years ago

@jackmatt2 Really? so no Object proxy anymore? sounds weird to me,

Anyway, I understand, I'll try to push this forward on next iteration.