Validatinator
Validatinator copied to clipboard
Validations which reference another field do not work when prepared from a config
This issue effects:
samedifferencerequiredIfrequiredIfNot
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.