Created
March 15, 2017 02:01
-
-
Save angelomachado/f9da3df258ed9126ba76592014e8de96 to your computer and use it in GitHub Desktop.
Mixin ember-cp-validations validators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { validator } from 'ember-cp-validations'; | |
export default { | |
email: [ | |
validator('presence', { | |
presence: true, | |
message: 'O email deve ser informado' | |
}), | |
validator('format', { | |
type: 'email', | |
message: 'Email inválido' | |
}) | |
] | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import { validator } from 'ember-cp-validations'; | |
import EmailValidations from './email-validator'; | |
const { assign } = Ember; | |
export default assign(EmailValidations, { | |
password: [ | |
validator('presence', { | |
presence: true, | |
message: 'A senha deve ser informada' | |
}), | |
validator('length', { | |
min: 8, | |
message: 'A senha deve possuir no mínimo 8 caracteres' | |
}) | |
] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//app/components/register-details.js | |
import Ember from 'ember'; | |
import { buildValidations } from 'ember-cp-validations'; | |
import UserValidations from 'auth/validators/user-validator'; | |
const Validations = buildValidations(UserValidations); | |
const { | |
Component, | |
computed, | |
get, | |
set | |
} = Ember; | |
export default Component.extend(Validations, { | |
didValidate: false, | |
email: null, | |
errors: null, | |
firstName: null, | |
lastName: null, | |
password: null, | |
passwordConfirmation: null, | |
actions: { | |
submit() { | |
this.validate().then(({ validations }) => { | |
if (get(validations, 'isValid')) { | |
// saving model | |
} else { | |
set(this, 'didValidate', true); | |
} | |
} | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import { validator } from 'ember-cp-validations'; | |
import LoginValidations from './login-validator'; | |
const { assign } = Ember; | |
export default assign(LoginValidations, { | |
firstName: [ | |
validator('presence', { | |
presence: true, | |
message: 'O nome deve ser informado' | |
}), | |
validator('length', { | |
min: 3, | |
message: 'O nome deve possuir no mínimo 3 caracteres' | |
}) | |
], | |
lastName: [ | |
validator('presence', { | |
presence: true, | |
message: 'O sobrenome deve ser informado' | |
}), | |
validator('length', { | |
min: 3, | |
message: 'O sobrenome deve possuir no mínimo 3 caracteres' | |
}) | |
], | |
passwordConfirmation: validator('confirmation', { | |
on: 'password', | |
message: 'A senha não confere' | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment