Implement regex validation conditions in form logic (#645)
* Implement regex validation conditions in form logic - Added support for 'matches_regex' and 'does_not_match_regex' conditions in FormPropertyLogicRule and FormLogicConditionChecker. - Updated validation logic to handle regex patterns, including error handling for invalid patterns. - Enhanced tests to cover scenarios for successful and failed regex validation, ensuring proper feedback for form submissions. - Updated JSON schema to include new regex condition types. These changes improve the flexibility of form validation by allowing regex-based conditions, enhancing user experience through more robust validation mechanisms. * update resource filters * Remove ray --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
14
client/lib/forms/FormLogicConditionChecker.js
vendored
14
client/lib/forms/FormLogicConditionChecker.js
vendored
@@ -278,6 +278,20 @@ function textConditionMet(propertyCondition, value) {
|
||||
return checkLength(propertyCondition, value, "<")
|
||||
case "content_length_less_than_or_equal_to":
|
||||
return checkLength(propertyCondition, value, "<=")
|
||||
case 'matches_regex':
|
||||
try {
|
||||
const regex = new RegExp(propertyCondition.value)
|
||||
return regex.test(value)
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
case 'does_not_match_regex':
|
||||
try {
|
||||
const regex = new RegExp(propertyCondition.value)
|
||||
return !regex.test(value)
|
||||
} catch (e) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user