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

[Breaking Change] Update RequiredIf Validator to Accept UDF/Closure and Update UDF Validator for Consistency When Handling Null/Empty Values #78

Closed
wants to merge 4 commits into from

Conversation

homestar9
Copy link
Contributor

@homestar9 homestar9 commented Sep 8, 2023

This change adds additional functionality to the RequiredIf validator. Now, you can pass a UDF/closure to the validator to dynamically evaluate whether the field is required or not. The UDF/closure should return true if the field is required and false if not.

Example:

myField = {
 // myField is required if today is Monday.
 requiredIf = function( value, target, errorMetadata ) {
        return dayOfWeekAsString( dayOfWeek( now() ) ) == "Monday";
 }
}

The UDF validator was also updated for consistency (see ortus-docs/cbvalidation-docs#13) and will treat null/empty values as valid. Developers who want to dynamically determine whether a field should be required will need to switch to using RequiredIf. This is a BREAKING change and should be reserved for the next major version of CBValidation.

homestar9 added a commit to homestar9/cbvalidation-docs that referenced this pull request Sep 8, 2023
Update `requireIf` validator to include option to pass a UDF/closure. (coldbox-modules/cbvalidation#78)
This is a breaking change designed to make the UDF validator consistent with other validators as discussed here (ortus-docs/cbvalidation-docs#13).

Developers should switch to the `requiredIf` validator if they need to dynamically evaluate whether a field should be required or not.
@homestar9 homestar9 force-pushed the development branch 2 times, most recently from dfc0b96 to 620072c Compare September 8, 2023 23:58
@homestar9 homestar9 changed the title Update RequiredIf Validator to Accept UDF/Closure Update RequiredIf Validator to Accept UDF/Closure and Update UDF Validator for Consistency Sep 9, 2023
@homestar9 homestar9 changed the title Update RequiredIf Validator to Accept UDF/Closure and Update UDF Validator for Consistency Update RequiredIf Validator to Accept UDF/Closure and Update UDF Validator for Consistency When Handling Null/Empty Values Sep 9, 2023
@homestar9 homestar9 changed the title Update RequiredIf Validator to Accept UDF/Closure and Update UDF Validator for Consistency When Handling Null/Empty Values [Breaking Change] Update RequiredIf Validator to Accept UDF/Closure and Update UDF Validator for Consistency When Handling Null/Empty Values Sep 9, 2023
@homestar9
Copy link
Contributor Author

This would be better if broken up into two pull requests. Closing.

@homestar9 homestar9 closed this Sep 9, 2023
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

Successfully merging this pull request may close these issues.

1 participant