Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customization of required rules #345

Open
jefersonralmeida opened this issue Sep 21, 2023 · 0 comments · May be fixed by #346
Open

Allow customization of required rules #345

jefersonralmeida opened this issue Sep 21, 2023 · 0 comments · May be fixed by #346

Comments

@jefersonralmeida
Copy link

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:

  1. Convert the local variable $require_type_of_rules inside GUMP::field_has_required_rules to a class property or const (that can be overridden on consumer class);
  2. Change the logic to consider any validator starting with required to 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant