Improve form property logic validation for checkbox conditions
- Update FormPropertyLogicRule to handle operators without values - Add support for checkbox conditions like 'is_checked' and 'is_not_checked' - Refactor logic validation in both API and client-side implementations - Remove unnecessary console.log statements - Update error modal text for better user experience
This commit is contained in:
51
client/lib/forms/FormPropertyLogicRule.js
vendored
51
client/lib/forms/FormPropertyLogicRule.js
vendored
@@ -22,6 +22,7 @@ class FormPropertyLogicRule {
|
||||
|
||||
isValid() {
|
||||
if (this.logic && this.logic["conditions"]) {
|
||||
console.log('logic', this.logic)
|
||||
this.checkConditions(this.logic["conditions"])
|
||||
this.checkActions(
|
||||
this.logic && this.logic["actions"] ? this.logic["actions"] : null,
|
||||
@@ -62,8 +63,7 @@ class FormPropertyLogicRule {
|
||||
condition["value"] === undefined ||
|
||||
condition["value"]["property_meta"] === undefined ||
|
||||
condition["value"]["property_meta"]["type"] === undefined ||
|
||||
condition["value"]["operator"] === undefined ||
|
||||
condition["value"]["value"] === undefined
|
||||
condition["value"]["operator"] === undefined
|
||||
) {
|
||||
this.isConditionCorrect = false
|
||||
return
|
||||
@@ -71,8 +71,7 @@ class FormPropertyLogicRule {
|
||||
|
||||
const typeField = condition["value"]["property_meta"]["type"]
|
||||
const operator = condition["value"]["operator"]
|
||||
const value = condition["value"]["value"]
|
||||
|
||||
|
||||
if (
|
||||
this.CONDITION_MAPPING[typeField] === undefined ||
|
||||
this.CONDITION_MAPPING[typeField]["comparators"][operator] === undefined
|
||||
@@ -81,23 +80,34 @@ class FormPropertyLogicRule {
|
||||
return
|
||||
}
|
||||
|
||||
const type =
|
||||
this.CONDITION_MAPPING[typeField]["comparators"][operator][
|
||||
"expected_type"
|
||||
]
|
||||
if (Array.isArray(type)) {
|
||||
let foundCorrectType = false
|
||||
type.forEach((subtype) => {
|
||||
if (this.valueHasCorrectType(subtype, value)) {
|
||||
foundCorrectType = true
|
||||
// Check if operator needs a value based on comparator definition
|
||||
const comparatorDef = this.CONDITION_MAPPING[typeField]["comparators"][operator]
|
||||
const needsValue = Object.keys(comparatorDef).length > 0
|
||||
|
||||
if (needsValue && condition["value"]["value"] === undefined) {
|
||||
this.isConditionCorrect = false
|
||||
return
|
||||
}
|
||||
|
||||
// Only check value type if comparator expects one
|
||||
if (needsValue) {
|
||||
const type = comparatorDef["expected_type"]
|
||||
const value = condition["value"]["value"]
|
||||
|
||||
if (Array.isArray(type)) {
|
||||
let foundCorrectType = false
|
||||
type.forEach((subtype) => {
|
||||
if (this.valueHasCorrectType(subtype, value)) {
|
||||
foundCorrectType = true
|
||||
}
|
||||
})
|
||||
if (!foundCorrectType) {
|
||||
this.isConditionCorrect = false
|
||||
}
|
||||
} else {
|
||||
if (!this.valueHasCorrectType(type, value)) {
|
||||
this.isConditionCorrect = false
|
||||
}
|
||||
})
|
||||
if (!foundCorrectType) {
|
||||
this.isConditionCorrect = false
|
||||
}
|
||||
} else {
|
||||
if (!this.valueHasCorrectType(type, value)) {
|
||||
this.isConditionCorrect = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,3 +161,4 @@ class FormPropertyLogicRule {
|
||||
}
|
||||
|
||||
export default FormPropertyLogicRule
|
||||
|
||||
|
||||
Reference in New Issue
Block a user