ember-form-components icon indicating copy to clipboard operation
ember-form-components copied to clipboard

Overloading of validationFields Array in EmberFormComponents.Form

Open lifeinafolder opened this issue 11 years ago • 2 comments

EmberFormComponents.Form = Ember.Mixin.create({
  showFieldValidation: false,
  validationFields: Ember.A(),
  isFormValid: function () {
    return !this.get('validationFields').any(function (field) {
      return !field.get('isValid');
    });
  }.property('[email protected]')
});

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 ?

lifeinafolder avatar Dec 27 '13 18:12 lifeinafolder

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

garth avatar Dec 27 '13 19:12 garth

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.

lifeinafolder avatar Dec 27 '13 21:12 lifeinafolder