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

Required field only if another field has a value, must be empty otherwise #7

Open
rap2hpoutre opened this issue Jan 24, 2018 · 1 comment

Comments

@rap2hpoutre
Copy link

Here is a question I asked on Stackoverflow about a validation rule. It seems it does not exists.


My question is about Laravel validation rules.

I have two inputs a and b. a is a select input with three possible values: x, y and z. I want to write this rule:

b must have a value only if a values is x.
And b must be empty otherwise.

Is there a way to write such a rule? I tried required_with, required_without but it seems it can not cover my case.

In other words, if the previous explanation was not clear enough:

  • If a == x, b must have a value.
  • If a != x, b must be empty.

Original Post: https://stackoverflow.com/questions/48420718/required-field-only-if-another-field-has-a-value-must-be-empty-otherwise


Is this kind of rule interesting for "Laravel Validation Rules"? It seems this collection of rule is about "things" (like credit card), not generic rules: so maybe such a rule does not have its place here. What do you think? Should I submit a PR?

@rap2hpoutre
Copy link
Author

Any news?

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

No branches or pull requests

1 participant