Skip to content

Allow customization of required rules #345

@jefersonralmeida

Description

@jefersonralmeida

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions