mardi 22 novembre 2016

How can I dynamically change validator options after creating in ember-cp-validations?

I need to change 'presence' option from 'true' to 'false' depending on dynamic form state. If formState == 'a' 'name' field is required, if == 'b' then not, and if I dynamically toggled formState, validator should change its option.

I tried do that, but it didn't help:

//form/component.js 
init() {
    this._super(...arguments);

    const Validations = buildValidations({
        name: validator('presence', {
        presence: Ember.computed('formState', function() {
            return this.get('formState') == 'a';
        })
     }),
    });

    // I use ember-validated-form-buffer for buffering changes
    this.set('formValues', formBufferProperty('model', Validations));
}

Is there any way to solve it?




Aucun commentaire:

Enregistrer un commentaire