bouncer icon indicating copy to clipboard operation
bouncer copied to clipboard

How can i validate two field is equal?

Open onur-km opened this issue 3 years ago • 2 comments

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

onur-km avatar Sep 29 '20 09:09 onur-km

		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?

onur-km avatar Sep 29 '20 09:09 onur-km

@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
}

dippas avatar Dec 19 '20 14:12 dippas