Skip to content

Beautiful Open-Source Form Builder

Content Length Logic Condition (#63)

Chirage073ca02a8f6
diff --git a/app/Rules/FormPropertyLogicRule.php b/app/Rules/FormPropertyLogicRule.php
index 1c3ed4052..5d3d30023 100644
--- a/app/Rules/FormPropertyLogicRule.php
+++ b/app/Rules/FormPropertyLogicRule.php
@@ -50,6 +50,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum',
'values' => [true]
]
+ ],
+ 'content_length_equals' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_does_not_equal' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than_or_equal_to' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than_or_equal_to' => [
+ 'expected_type' => 'number'
]
]
],
@@ -86,6 +104,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum',
'values' => [true]
]
+ ],
+ 'content_length_equals' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_does_not_equal' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than_or_equal_to' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than_or_equal_to' => [
+ 'expected_type' => 'number'
]
]
],
@@ -122,6 +158,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum',
'values' => [true]
]
+ ],
+ 'content_length_equals' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_does_not_equal' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than_or_equal_to' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than_or_equal_to' => [
+ 'expected_type' => 'number'
]
]
],
@@ -158,6 +212,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum',
'values' => [true]
]
+ ],
+ 'content_length_equals' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_does_not_equal' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than_or_equal_to' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than_or_equal_to' => [
+ 'expected_type' => 'number'
]
]
],
@@ -194,6 +266,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum',
'values' => [true]
]
+ ],
+ 'content_length_equals' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_does_not_equal' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_greater_than_or_equal_to' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than' => [
+ 'expected_type' => 'number'
+ ],
+ 'content_length_less_than_or_equal_to' => [
+ 'expected_type' => 'number'
]
]
],
diff --git a/app/Service/Forms/FormLogicConditionChecker.php b/app/Service/Forms/FormLogicConditionChecker.php
index ba201047b..d2edd7fc9 100644
--- a/app/Service/Forms/FormLogicConditionChecker.php
+++ b/app/Service/Forms/FormLogicConditionChecker.php
@@ -173,6 +173,25 @@ class FormLogicConditionChecker
return ($fieldDate >= now()->toDateString() && $fieldDate <= now()->addYears(1)->toDateString());
}
+ private function checkLength ($condition, $fieldValue, $operator = '==='): bool {
+ if(!$fieldValue || strlen($fieldValue) === 0) return false;
+ switch ($operator) {
+ case '===':
+ return strlen($fieldValue) === (int)$condition['value'];
+ case '!==':
+ return strlen($fieldValue) !== (int)$condition['value'];
+ case '>':
+ return strlen($fieldValue) > (int)$condition['value'];
+ case '>=':
+ return strlen($fieldValue) >= (int)$condition['value'];
+ case '<':
+ return strlen($fieldValue) < (int)$condition['value'];
+ case '<=':
+ return strlen($fieldValue) <= (int)$condition['value'];
+ }
+ return false;
+ }
+
private function textConditionMet (array $propertyCondition, $value): bool {
switch ($propertyCondition['operator']) {
@@ -192,6 +211,18 @@ class FormLogicConditionChecker
return $this->checkIsEmpty($propertyCondition, $value);
case 'is_not_empty':
return !$this->checkIsEmpty($propertyCondition, $value);
+ case 'content_length_equals':
+ return $this->checkLength($propertyCondition, $value, '===');
+ case 'content_length_does_not_equal':
+ return $this->checkLength($propertyCondition, $value, '!==');
+ case 'content_length_greater_than':
+ return $this->checkLength($propertyCondition, $value, '>');
+ case 'content_length_greater_than_or_equal_to':
+ return $this->checkLength($propertyCondition, $value, '>=');
+ case 'content_length_less_than':
+ return $this->checkLength($propertyCondition, $value, '<');
+ case 'content_length_less_than_or_equal_to':
+ return $this->checkLength($propertyCondition, $value, '<=');
}
return false;
}
@@ -214,6 +245,18 @@ class FormLogicConditionChecker
return $this->checkIsEmpty($propertyCondition, $value);
case 'is_not_empty':
return !$this->checkIsEmpty($propertyCondition, $value);
+ case 'content_length_equals':
+ return $this->checkLength($propertyCondition, $value, '===');
+ case 'content_length_does_not_equal':
+ return $this->checkLength($propertyCondition, $value, '!==');
+ case 'content_length_greater_than':
+ return $this->checkLength($propertyCondition, $value, '>');
+ case 'content_length_greater_than_or_equal_to':
+ return $this->checkLength($propertyCondition, $value, '>=');
+ case 'content_length_less_than':
+ return $this->checkLength($propertyCondition, $value, '<');
+ case 'content_length_less_than_or_equal_to':
+ return $this->checkLength($propertyCondition, $value, '<=');
}
return false;
}
diff --git a/resources/data/open_filters.json b/resources/data/open_filters.json
index 78c42ab97..16291fb66 100644
--- a/resources/data/open_filters.json
+++ b/resources/data/open_filters.json
@@ -36,6 +36,24 @@
true
]
}
+ },
+ "content_length_equals": {
+ "expected_type": "number"
+ },
+ "content_length_does_not_equal": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than_or_equal_to": {
+ "expected_type": "number"
+ },
+ "content_length_less_than": {
+ "expected_type": "number"
+ },
+ "content_length_less_than_or_equal_to": {
+ "expected_type": "number"
}
}
},
@@ -76,6 +94,24 @@
true
]
}
+ },
+ "content_length_equals": {
+ "expected_type": "number"
+ },
+ "content_length_does_not_equal": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than_or_equal_to": {
+ "expected_type": "number"
+ },
+ "content_length_less_than": {
+ "expected_type": "number"
+ },
+ "content_length_less_than_or_equal_to": {
+ "expected_type": "number"
}
}
},
@@ -116,6 +152,24 @@
true
]
}
+ },
+ "content_length_equals": {
+ "expected_type": "number"
+ },
+ "content_length_does_not_equal": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than_or_equal_to": {
+ "expected_type": "number"
+ },
+ "content_length_less_than": {
+ "expected_type": "number"
+ },
+ "content_length_less_than_or_equal_to": {
+ "expected_type": "number"
}
}
},
@@ -156,6 +210,24 @@
true
]
}
+ },
+ "content_length_equals": {
+ "expected_type": "number"
+ },
+ "content_length_does_not_equal": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than_or_equal_to": {
+ "expected_type": "number"
+ },
+ "content_length_less_than": {
+ "expected_type": "number"
+ },
+ "content_length_less_than_or_equal_to": {
+ "expected_type": "number"
}
}
},
@@ -196,6 +268,24 @@
true
]
}
+ },
+ "content_length_equals": {
+ "expected_type": "number"
+ },
+ "content_length_does_not_equal": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than": {
+ "expected_type": "number"
+ },
+ "content_length_greater_than_or_equal_to": {
+ "expected_type": "number"
+ },
+ "content_length_less_than": {
+ "expected_type": "number"
+ },
+ "content_length_less_than_or_equal_to": {
+ "expected_type": "number"
}
}
},
diff --git a/resources/js/forms/FormLogicConditionChecker.js b/resources/js/forms/FormLogicConditionChecker.js
index dadd2e578..bfce0fc14 100644
--- a/resources/js/forms/FormLogicConditionChecker.js
+++ b/resources/js/forms/FormLogicConditionChecker.js
@@ -159,6 +159,25 @@ function checkNextYear (condition, fieldValue) {
return (fieldDate >= today && fieldDate <= new Date(today.getFullYear() + 1, today.getMonth(), today.getDate()))
}
+function checkLength (condition, fieldValue, operator = '===') {
+ if(!fieldValue || fieldValue.length === 0) return false;
+ switch (operator) {
+ case '===':
+ return fieldValue.length === parseInt(condition.value)
+ case '!==':
+ return fieldValue.length !== parseInt(condition.value)
+ case '>':
+ return fieldValue.length > parseInt(condition.value)
+ case '>=':
+ return fieldValue.length >= parseInt(condition.value)
+ case '<':
+ return fieldValue.length < parseInt(condition.value)
+ case '<=':
+ return fieldValue.length <= parseInt(condition.value)
+ }
+ return false
+}
+
function textConditionMet (propertyCondition, value) {
switch (propertyCondition.operator) {
case 'equals':
@@ -177,6 +196,18 @@ function textConditionMet (propertyCondition, value) {
return checkIsEmpty(propertyCondition, value)
case 'is_not_empty':
return !checkIsEmpty(propertyCondition, value)
+ case 'content_length_equals':
+ return checkLength(propertyCondition, value, '===')
+ case 'content_length_does_not_equal':
+ return checkLength(propertyCondition, value, '!==')
+ case 'content_length_greater_than':
+ return checkLength(propertyCondition, value, '>')
+ case 'content_length_greater_than_or_equal_to':
+ return checkLength(propertyCondition, value, '>=')
+ case 'content_length_less_than':
+ return checkLength(propertyCondition, value, '<')
+ case 'content_length_less_than_or_equal_to':
+ return checkLength(propertyCondition, value, '<=')
}
return false
}
@@ -198,7 +229,19 @@ function numberConditionMet (propertyCondition, value) {
case 'is_empty':
return checkIsEmpty(propertyCondition, value)
case 'is_not_empty':
- return !checkIsEmpty(propertyCondition, value)
+ return checkIsEmpty(propertyCondition, value)
+ case 'content_length_equals':
+ return checkLength(propertyCondition, value, '===')
+ case 'content_length_does_not_equal':
+ return checkLength(propertyCondition, value, '!==')
+ case 'content_length_greater_than':
+ return checkLength(propertyCondition, value, '>')
+ case 'content_length_greater_than_or_equal_to':
+ return checkLength(propertyCondition, value, '>=')
+ case 'content_length_less_than':
+ return checkLength(propertyCondition, value, '<')
+ case 'content_length_less_than_or_equal_to':
+ return checkLength(propertyCondition, value, '<=')
}
return false
}