jeudi 17 août 2017

ember-cp-validations how to validate dropdown menu?

In my ember app, I am using ember-cp-validations for form validation purpose. I have 2 question with ember-cp-validations

  1. How to validate a select option?
  2. when clicking on check button we show the error. but how can i remove the error once the value is true? ( when user enter the value in the age i would like to hide the error )

Live example

My component code :

import Ember from 'ember';
import Validations from './my-validations';

export default Ember.Component.extend(Validations,{
  content: [
    {"name":"Apple","id":1},
    {"name":"Banana","id":2},
    {"name":"Orange","id":3},
    {"name":"Pineapple","id":4},
    {"name":"Gova","id":5}
  ],
  selectedValue:null,
  num: null,
  email: null,
  message: '',
  emailMessage: '',
  actions: {
    change(){},
    check(){
      this.set('message','');
      this.set('emailMessage','');
      this.validate().then(({model, validations})=>{
        if(validations.get('isValid')){
          this.set('message','');
          this.set('emailMessage','');
        }
        else{
          if(model.get('validations.attrs.num.isInvalid')){
            this.set('message',model.get('validations.attrs.num.messages'));
          }
          if(model.get('validations.attrs.email.isInvalid')){
            this.set('emailMessage',model.get('validations.attrs.email.messages'));
          }
        }
      },(errors)=>{
        console.log(errors);
      });
    }
  }
});




Aucun commentaire:

Enregistrer un commentaire