Skip to content

Beautiful Open-Source Form Builder

Fix logic operator issue (#104)

Chirag Chhatrala825492bf45ab
diff --git a/app/Rules/FormPropertyLogicRule.php b/app/Rules/FormPropertyLogicRule.php
index fae01c010..6e0784d23 100644
--- a/app/Rules/FormPropertyLogicRule.php
+++ b/app/Rules/FormPropertyLogicRule.php
@@ -562,7 +562,7 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
private function checkConditions($conditions)
{
- if (isset($conditions['operatorIdentifier'])) {
+ if (array_key_exists('operatorIdentifier', $conditions)) {
if (($conditions['operatorIdentifier'] !== 'and') && ($conditions['operatorIdentifier'] !== 'or')) {
$this->conditionErrors[] = 'missing operator';
$this->isConditionCorrect = false;
diff --git a/tests/Feature/Forms/FormPropertyLogicTest.php b/tests/Feature/Forms/FormPropertyLogicTest.php
index 430aea145..ad3b1d7f2 100644
--- a/tests/Feature/Forms/FormPropertyLogicTest.php
+++ b/tests/Feature/Forms/FormPropertyLogicTest.php
@@ -135,4 +135,38 @@ it('can validate form logic rules for conditions', function () {
$validatorObj = $this->app['validator']->make($data, $rules);
$this->assertFalse($validatorObj->passes());
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe("The logic conditions for Name are not complete. Error detail(s): missing condition value");
+
+ $data = [
+ 'properties' => [
+ [
+ 'id' => "title",
+ 'name' => "Name",
+ 'type' => 'text',
+ 'hidden' => false,
+ 'required' => false,
+ 'logic' => [
+ "conditions" => [
+ "operatorIdentifier"=> null,
+ "children"=> [
+ [
+ "identifier"=> "title",
+ "value"=> [
+ "operator"=> "starts_with",
+ "property_meta"=> [
+ "id"=> "title",
+ "type"=> "text"
+ ],
+ ]
+ ]
+ ]
+ ],
+ "actions" => []
+ ]
+ ]
+ ]
+ ];
+
+ $validatorObj = $this->app['validator']->make($data, $rules);
+ $this->assertFalse($validatorObj->passes());
+ expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe("The logic conditions for Name are not complete. Error detail(s): missing operator");
});
\ No newline at end of file