1

I'm using ember-validations and what is in Ember the right way to use the same validation rules between Add and Edit controller?

Doing this it is not the DRY way

App.UsersAddUserController.reopen(Ember.Validations.Mixin, {
    validations: {
        name: {
            presence: true,
            length: { minimum: 3 }
        },
        surname: {
            presence: true,
            length: { minimum: 3 }
        }
    },
});

App.UsersEditUserController.reopen(Ember.Validations.Mixin, {
    validations: {
        name: {
            presence: true,
            length: { minimum: 3 }
        },
        surname: {
            presence: true,
            length: { minimum: 3 }
        }
    },
});
wasabigeek
  • 2,923
  • 1
  • 21
  • 30
Massimiliano Marini
  • 499
  • 1
  • 6
  • 16

2 Answers2

0

Either

App.UsersEditUserController = App.UsersAddUserController.extend({})

Or Tell route which controller to use

App.UsersEditUserRoute = Ember.Route.extend({
  controllerName: 'usersAddUser'
})
Manoharan
  • 388
  • 1
  • 12
0

Do it this way:

App.UserValidations = {
  validations: {
    name: {
      presence: true,
      length: { minimum: 3 }
    },
    surname: {
      presence: true,
      length: { minimum: 3 }
    }
  }
}

App.UsersAddUserController.reopen(Ember.Validations.Mixin, App.UserValidations);
App.UsersEditUserController.reopen(Ember.Validations.Mixin, App.UserValidations);
dan
  • 1,028
  • 8
  • 15