Skip to content

Conversation

@max13fr
Copy link
Contributor

@max13fr max13fr commented Feb 25, 2025

Hello,

I added the support for the "sometimes" validator rule that allow to skip all following validators like "required".

Currently, a field with this following rules was consired as required (but it shouldn't) :

  • 'consent_cgu' => 'sometimes|accepted'
  • 'other_field' => 'sometimes|required|...' ("filled" rule seems better for this case but "filled_if", "filled_with", ... not existing so it's not an universal solution).

It notably fix this issue without any change to follow Laravel behaviour : #343

As Laravel behaviour, the following rules is correctly returned as required : 'badrule'=> 'required|sometimes|...'

Best regard

@shalvah
Copy link
Contributor

shalvah commented Jul 28, 2025

Hey, sorry I missed this. I'm a bit reluctant to add another parameter, sometimes to the validation logic. Why not simplify this to: if sometimes is provided, set required to false (unless it was already true) ?

@max13fr
Copy link
Contributor Author

max13fr commented Jul 29, 2025

Hi, no worries.

Why not simplify this to: if sometimes is provided, set required to false (unless it was already true) ?

Because the case "sometimes|accepted" would not be managed for example :

  • first "sometimes" set required to false
  • then "accepeted" set required to true

As "sometimes" is almost always at the beginning, changing required to false is useless (since it is already false by default) but on the other hand it risks being overwritten behind (accepted, required, ...).

@shalvah
Copy link
Contributor

shalvah commented Jul 29, 2025

Can you add a test?

@max13fr
Copy link
Contributor Author

max13fr commented Oct 18, 2025

Hello,

Sorry for the delay, I've been very busy these past few months.

I just added the tests.

Best regards

@shalvah
Copy link
Contributor

shalvah commented Oct 20, 2025

I've been very busy these past few months.

Haha, so have I! Thanks!

@shalvah shalvah merged commit 5f2cf63 into knuckleswtf:v5 Oct 20, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants