garth / ember-form-components

Reusable form components for emberjs with built in validation
MIT License
17 stars 3 forks source link

Overloading of validationFields Array in EmberFormComponents.Form #6

Open lifeinafolder opened 10 years ago

lifeinafolder commented 10 years ago
EmberFormComponents.Form = Ember.Mixin.create({
  showFieldValidation: false,
  validationFields: Ember.A(),
  isFormValid: function () {
    return !this.get('validationFields').any(function (field) {
      return !field.get('isValid');
    });
  }.property('validationFields.@each.isValid')
});

Lets say two controllers A & B mix the above Mixin. These controllers are for routes A & B.

If route B is visited after route A, its "validationFields" will already be populated with fields present in route A.

This is bad as now route B is sort of impacted by behavior of validations fields on route A.

Each controller should have its own copy of validationFields for just its own view, no ?

garth commented 10 years ago

Yes, perhaps each controller needs to init validationFields as a new Ember.A()?

lifeinafolder commented 10 years ago

I think so but once you move that property out of the mixin, the mixin needs to explicitly declare that the class using it should have it. Besides documentation, there is no easy way to have it.

I think it might be better to convert that mixin to a class. Each controller should extend from it.