ember-cp-validations icon indicating copy to clipboard operation
ember-cp-validations copied to clipboard

Validations are not showing on validate action

Open zion03 opened this issue 5 years ago • 0 comments

DEBUG: Ember : 3.14.1 index.js:194 DEBUG: Ember Data : 3.13.1 index.js:194 DEBUG: jQuery : 3.4.1 index.js:194 DEBUG: Ember Bootstrap : 2.8.1 index.js:194 DEBUG: Ember Simple Auth : 2.1.0 "ember-cp-validations": "^4.0.0-beta.10",

Validator works as expected, but only when I click on specific field. So If I click submit button without fill any field - there no error notification (but validation return "false" - not valid). In the past versions this.set('didValidate', true); - solved this problem.

const Validations = buildValidations({
  name: {
    debounce: 500,
    validators: [
      validator('presence', true)
    ]
  },
  email: {
    debounce: 200,
    validators: [
      validator('presence', true),
      validator('ds-error'),
      validator('format', {
        type: 'email'
      })
    ]
  }
});

export default Component.extend(Validations,{
  store: service(),
  actions: {
    reg() {
      this.validate().then(({ model, validations }) => {
        if (!validations.get('isValid')){return; }
        let user = this.get('store').createRecord('user', ...
<form {{action 'reg' on='submit'}}>
 {{validated-input model=this valuePath='name' placeholder='name'}}
 {{validated-input model=this valuePath='email' placeholder='Email'}}
</form>

UPDATE:

So the problem was in validated-input.js, didValidate si not computed anymore. Add didValidate to each validated-input solve problem:

<form {{action 'reg' on='submit'}}>
 {{validated-input model=this valuePath='name' placeholder='name' didValidate=didValidate}}
 {{validated-input model=this valuePath='email' placeholder='Email' didValidate=didValidate}}
</form>

Is this solution is right way to show validations? Thanks!

zion03 avatar Nov 14 '19 22:11 zion03