[11.x] Prohibited If Declined and Prohibited If Accepted validation rules #54608
+142
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
prohibited_if_accepted
andprohibited_if_declined
Description
The
prohibited_if_accepted
andprohibited_if_declined
validation rules are introduced to simplify the logic of prohibiting a field based on boolean-like values (accepted
anddeclined
). These rules are designed to make the validation more intuitive when dealing with specific conditions where fields should be prohibited if another field has the value of "accepted" (e.g.,yes
,1
,true
) or "declined" (e.g.,no
,0
,false
).Current Prohibited If Validation
Currently, to implement the same functionality with
prohibited_if
, you would need to explicitly list the possible truthy and falsy values of a boolean field like so:For Prohibiting When Accepted (Boolean
true
):For Prohibiting When Declined (Boolean
false
):While this works, it requires manually specifying all the possible representations of "accepted" and "declined", which can be cumbersome and makes the code harder to read.
Prohibited If Accepted / Declined Validation
With the addition of these two new rules, the validation becomes cleaner and more readable.
prohibited_if_accepted
This rule will prohibit the field if the other field is "accepted" (i.e., has a truthy value, such as
yes
,1
,true
, etc.).prohibited_if_declined
This rule will prohibit the field if the other field is "declined" (i.e., has a falsy value, such as
no
,0
,false
, etc.).Conclusion
By introducing
prohibited_if_accepted
andprohibited_if_declined
, we make the validation syntax more intuitive and easier to read, especially when dealing with boolean-like values that represent "acceptance" or "decline". These new rules streamline the logic, avoiding the need to list out all possible representations of true or false.These rules were inspired by the existing
required_if_accepted
andrequired_if_declined
validation rules, which similarly simplify handling acceptance and declination conditions in validation.This update improves code readability, reduces boilerplate, and provides a clearer way to enforce validation based on the acceptance or declination of a related field.