Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if a validator is disabled #644

Open
epyx25 opened this issue Jun 5, 2019 · 0 comments
Open

Check if a validator is disabled #644

epyx25 opened this issue Jun 5, 2019 · 0 comments

Comments

@epyx25
Copy link

epyx25 commented Jun 5, 2019

I have a model, with a description field, which is some time is required.

model.js

description: validator('presence', {
    presence: true,
    disabled(model) {
      return this.get('model.simple')
    }
  }),

In my {{form-group}} component the label has a class, if the field is required. (It depends on if the model has a validation on the property)

components/form-group.js

  init() {
    this._super(...arguments);
    var valuePath = this.get('property');
    defineProperty(this, 'required', computed.oneWay(`model.validations.attrs.${valuePath}`));
  },
  hasValidationClass: computed('required', function(){
    return this.get('required') ? 'has-error' : '';
  }),

components/form-group.hbs

{{#if label}}
  <label class="{{labelClass}} {{hasValidationClass}} control-label">
    {{label}}
  </label>
{{/if}}

Is there a way to find out if the validator is disabled or not, so I could do something like this?

components/form-group.js

  hasValidationClass: computed('required', function(){
    return this.get('required') && !this.get('required.disabled') ? 'has-error' : '';
  }),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant