dimanche 20 août 2017

cp-validation not working as expected

I am integrating the cp-validaiton with my ember app. but I am not getting any response. any one help me here.

my route js :

import Ember from 'ember';
import Validations from '../validation'

export default Ember.Route.extend(Validations, {
  num:null,
    message: '',
  model(){
    return { num:null}
  },
  actions:{ 
    check(){
        this.set('message','');

      this.validate().then(({model, validations})=>{
        if(validations.get('isValid')){
          console.log('statge', validations.get('isValid') )
                    this.set('message','');
                }else{
        if(model.get('validations.attrs.num.isInvalid')){
                        this.set('message',model.get('validations.attrs.num.messages'));
                    }
        }
      })
    }
  }
});

my validation.js :

import { validator, buildValidations } from 'ember-cp-validations';

export default buildValidations({
    num: [
        validator('number',{
        allowString: true,
        integer: true,
        message: 'Error! This is not an integer!'
}),
    validator('presence', true)
]
});

template :

<h1>This is my Route</h1>

Enter Age:<br>
<br>
<div style='color: red'><br></div>
<button >Check</button><br>

Live in Twiddle




Aucun commentaire:

Enregistrer un commentaire