Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Cross field validation not working #26

Open
MrToxy opened this issue Dec 3, 2019 · 0 comments
Open

Cross field validation not working #26

MrToxy opened this issue Dec 3, 2019 · 0 comments

Comments

@MrToxy
Copy link

MrToxy commented Dec 3, 2019

Trying to use cross-field validation to validate a password and password confirmation field but it's not working, the target/ref to refer doesn't actually return its value.

On the template I have:

<validation-observer ref="observer" v-slot="{invalid}" class="validation-observer" @submit.prevent="validate">
  <form class="standard-form">
    <div class="form-row">
      <div class="form-item">
        <h-text-field v-model="form.password" type="password" name="password" label="Password:" placeholder="Password" />
      </div>
    </div>
    <div class="form-row">
      <div class="form-item">
        <h-text-field v-model="form.password_confirmation" type="password" name="password_confirmation" label="Password Confirmation:" placeholder="Password Confirmation" />
      </div>
    </div>
    <button class="modern-cta-btn">
      Submit
    </button>
  </form>
</validation-observer>

the <h-text-field/> component simply renders a <ValidationProvider> with the rules for the fields and the name provided as prop.

And the rules are:

	password: 'required|password:password_confirmation',
	password_confirmation: 'required',

As per https://logaretm.github.io/vee-validate/advanced/cross-field-validation.html#targeting-other-fields I reference the password_confirmation (the name of the ValidationProvider) as an argument to that validation rule.

The validation rule:

/plugins/vee-validate.js

export default ({app}) => {
	app.validator.extend('password', {
                 params: ['target'],
		validate(value, [target]) {
			console.log('e: ', target);
			return true;
		},
		getMessage: () => 'Password confirmation does not match',
	});
}

The target always logs the name of the param password_confirmation instead of the actual value of that field

image

An overview of the setup

image

The last two fields are the password and the password confirmation

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant