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

Issues with validators

Open davidma415 opened this issue 4 years ago • 0 comments

Code Snippet

  @tracked model = {
    newPassword: '',
    confirmPassword: ''
  };
  @tracked validatorsAreLoaded = false;
  constructor() {
    super(...arguments);
    this.createFormValidations();
  }
  async createFormValidations() {
    await this.passwordStrength.load();
    this.setPasswordValidation = {
      newPassword: [
        validatePresence({presence: true}),
        validateLength({
          min: this.minLength,
          max: this.maxLength
        }),
        validatePasswordStrength({
          minScore: 3,
          passwordStrengthService: this.passwordStrength,
          passwordStrengthResults: this.passwordStrengthResult,
          message: this.intl.lookup('validations.passwordStrength')
        })],
      confirmPassword: [
        validateConfirmation({
          on: 'newPassword',
          message: this.intl.lookup('validations.passwordsDoNotMatch')
        })]
    };
    this.formChangeset = new Changeset(
      this.model,
      lookupValidator(this.setPasswordValidation),
      this.setPasswordValidation
    );
    this.validatorsAreLoaded = true;
  }

Version

3.10.0

Expected Behavior

Expect it to validate the new password / confirm password with the validators.

Actual Behavior

The only validator that runs is validatePasswordStrength which is a custom validator I've created. Any help would be appreciated. validateConfirmation always evaluates to true even when there's nothing in newPassword, and newPassword doesn't seem to be evaluated either.

davidma415 avatar Dec 02 '20 22:12 davidma415