Skip to content

Setting to make 'optional' state default? #1247

Closed

Description

@alystair

Whilst reviewing the documentation it seems having everything set as 'optional' was the default in older releases - I'm finding in my own use cases is that this would be preferred, as wrapping v::optional around almost every validator is way too verbose.

Are there plans to add a setting to make things optional by default? If there are not, what would be the pref. way to extend the validator to make such a setting? Eg. v::allOptional(true);

Somewhat related - the documentation for validating object attributes does not mention the (ironically optional) 'mandatory' boolean.

Activity

  1. alganet commented on Feb 20, 2023

    @alganet
    Member

    I would like more feedback before implementing this. I was behind the decision to make everything optional in older releases, as I prefer that approach as well, but it seems to confuse most of the users.

    This behavior "lives" in each rule, and it is not something central. It is more a mindset than a piece of code. Some rules still have remains of being optional (like the attribute and key you mentioned). It is very likely that we're going to make them mandatory by default in future releases.

    To support both approaches, we would need a different Validatable interface, with some method to be implemented by all rules that defines the behavior when optionals are turned on. It might get complicated.

    I'll keep this open for a while, and I might convert it to a discussion in GitHub discussions so it can be a long-lived theme.

  2. locked and limited conversation to collaborators on Mar 11, 2024
  3. converted this issue into a discussion #1451 on Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions