-
Notifications
You must be signed in to change notification settings - Fork 341
Description
I was trying to implement a required_with/optional_with custom validator, that would make a field required if another field is present or optional if another field is present.
I got blocked by the fact that the only rules that always run even when the field is not set are 'required' and 'required_file' (hard-coded inside GUMP::field_has_required_rules).
My first try was to override this method, but it's private...:(
My proposal is to give the consumer of the library the option to define which validators should be tagged as "required" (in the sense that they will run even if the field is not present).
I see two solutions for that:
- Convert the local variable
$require_type_of_rulesinsideGUMP::field_has_required_rulesto a class property or const (that can be overridden on consumer class); - Change the logic to consider any validator starting with
requiredto always run (even if the field is not present).
My vote is for the first option...
I'll place a PR with the change...
Ps.: Those validators could be included by default in the library since they're super useful. Please tell me if it's interesting, then I can place a PR for that.
Thanks.