In the last tip, i talked about the awesome addon ember-changeset, there is a companion addon to add validations to your changeset.
Install the addon with
Then you can wire up your model validator
Then create your validator
Try it out and let me know how it works. Do you have a better way to handle validations?
ember-changeset-validations at https://github.com/DockYard/ember-changeset-validations
Ember Changeset Tip 61
Install the addon with
1 |
ember install ember-changeset-validations |
Then you can wire up your model validator
1 2 3 4 5 |
{{dummy-form changeset=(changeset user EmployeeValidations) submit=(action "submit") rollback=(action "rollback") }} |
Then create your validator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// validations/employee.js import { validatePresence, validateLength, validateConfirmation, validateFormat } from 'ember-changeset-validations/validators'; export default { firstName: [ validatePresence(true), validateLength({ min: 4 }) ], lastName: validatePresence(true), email: validateFormat({ type: 'email' }), password: validateLength({ min: 8 }), passwordConfirmation: validateConfirmation({ on: 'password' }) }; |
Try it out and let me know how it works. Do you have a better way to handle validations?
ember-changeset-validations at https://github.com/DockYard/ember-changeset-validations
Ember Changeset Tip 61
Also published on Medium.