KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Is there a way to send multiple values to the `validationFunction` on `CustomValidation` #3031

Open KD opened this topic on on Apr 7, 2023 - 3 comments

KD commented on Apr 7, 2023

Please assist me in validating the same character for both the new and confirm password fields... In the current version, the validationFunction only accepts a single argument, but I would like to send both values and show I can compare them...

CustomValidator::create("confirmPasswordMatch")
                ->inputToValidate("newPassword")
                ->inputToValidate("confirmPassword")
                ->validationFunction(function ($value, $value2) {
                    return ($value == $value2)?true:false;
                })
                ->validationGroup("vGroup")
                ->errorMessage("Password and Confirm Password does not match!"),

I really appreciate any help you can provide.

KoolReport commented on Apr 11, 2023

I will consult dev.team about this and come back to you.

KD commented on Apr 11, 2023

thank you

KoolReport commented on Apr 11, 2023

Here is the answer from dev.team, you can do this:

CustomValidator::create("confirmPasswordMatch")
                ->inputToValidate("newPassword")
                ->validationFunction(function ($value) {
                    return ($value == $this->sibling("confirmPassword")->value())?true:false;
                })
                ->validationGroup("vGroup")
                ->errorMessage("Password and Confirm Password does not match!")

So we put custom validator to newPassword and inside the validation function, you access the confirmPassword value with $this->sibling("confirmPassword"). At the nutshell, the validator object is actually an widget added to dashboard.

Let us know if you need further assistance.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Inputs