Validatinator icon indicating copy to clipboard operation
Validatinator copied to clipboard

Validations which reference another field do not work when prepared from a config

Open mpriour opened this issue 3 years ago • 0 comments

This issue effects:

  • same
  • difference
  • requiredIf
  • requiredIfNot

In all of these methods the otherField parameter is expected to be an HTMLInputElement. However, when the validation method is prepared from a string via the config, this parameter is a string. For example:

{
  ".my-form": {
    ".my-field-selector": "required|same:.other-field-selector",
   }
}
/* is parsed to */
[
   ["required"],
   ["same", ".other-field-selector"]
]

/* Then the validation is called like this */
HTMLFormValidations.same(form, field, ".other-field-selector")

/* Within the "same" method this becomes */
...
field.value == ".other-field-selector".value
...

/* This always evaluates to false since strings do not have a "value" property */

Similar issues are present in the other methods.

I'm happy to provide a PR which will address these issues.

mpriour avatar Aug 10 '22 16:08 mpriour