As I'm building form elements dynamically I want to be able to check and see if a form field is required or not via a custom validation rule. The problem is that when I add a custom validation rule, it forces the field to not be empty. If I allow the field to be empty, it doesn't check my custom validator unless something is entered in the field.
How can I check in a callback whether to allow or not a field as required?
In my SubmissionsTable
public function validationDefault(Validator $validator)
{
$validator
->add("custom_value_q", [
"custom" => [
"rule" => [$this, "customFieldIsRequired"],
"message" => "Message Here"
]
]
);
return $validator;
}
public function customFieldIsRequired($value, $context)
{
//logic here
return true;
}