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

How can i validate two field is equal? #63

Open
onur-km opened this issue Sep 29, 2020 · 2 comments
Open

How can i validate two field is equal? #63

onur-km opened this issue Sep 29, 2020 · 2 comments

Comments

@onur-km
Copy link

onur-km commented Sep 29, 2020

With custom validation: How can i validate two field is equal?

@onur-km
Copy link
Author

onur-km commented Sep 29, 2020

		customValidations: 
		{
			isEqualPw: function (field) 
			{
				if(field.id == 're-password' && field.value !== field.closest('form').querySelector('#password').value)
				{
					return true;
				}
			}
		},
		messages: 
		{
			isEqualPw: 'no equal pw',
		}

You can known more easly way?

@dippas
Copy link

dippas commented Dec 19, 2020

@onur-km you can use this:

compareFields: field => {
  const selector = field.dataset.equalto,
  otherField = field.form.querySelector(selector)

  if (!selector || !otherField) return false
  return otherField.value !== field.value
}

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

2 participants