Skip to content

Beautiful Open-Source Form Builder

ESC-575 If operator has no format and no expected_type, it means it doesn't n… (#767)

Chirag Chhatralacac88e7a3c74
diff --git a/api/app/Rules/IntegrationLogicRule.php b/api/app/Rules/IntegrationLogicRule.php
index 6fc67705a..be0a12127 100644
--- a/api/app/Rules/IntegrationLogicRule.php
+++ b/api/app/Rules/IntegrationLogicRule.php
@@ -47,6 +47,14 @@ class IntegrationLogicRule implements DataAwareRule, ValidationRule
return;
}
+ $typeField = $condition['value']['property_meta']['type'];
+ $operator = $condition['value']['operator'];
+
+ // If operator has no format and no expected_type, it means it doesn't need input
+ if (!isset(FormPropertyLogicRule::getConditionMapping()[$typeField]['comparators'][$operator]['expected_type'])) {
+ return;
+ }
+
if (!isset($condition['value']['value'])) {
$this->isConditionCorrect = false;
$this->conditionErrors[] = 'missing condition value';
@@ -54,8 +62,6 @@ class IntegrationLogicRule implements DataAwareRule, ValidationRule
return;
}
- $typeField = $condition['value']['property_meta']['type'];
- $operator = $condition['value']['operator'];
$value = $condition['value']['value'];
if (!isset(FormPropertyLogicRule::getConditionMapping()[$typeField])) {
diff --git a/api/tests/Feature/Forms/FormIntegrationTest.php b/api/tests/Feature/Forms/FormIntegrationTest.php
index 5d1914803..34278822b 100644
--- a/api/tests/Feature/Forms/FormIntegrationTest.php
+++ b/api/tests/Feature/Forms/FormIntegrationTest.php
@@ -45,3 +45,58 @@ it('can CRUD form integration', function () {
'message' => 'Form Integration was deleted.'
]);
});
+
+it('can create form integration with checkbox logic', function () {
+ $user = $this->actingAsProUser();
+ $workspace = $this->createUserWorkspace($user);
+ $form = $this->createForm($user, $workspace, [
+ 'properties' => [
+ [
+ 'id' => 'checkbox_field',
+ 'name' => 'Checkbox Field',
+ 'type' => 'checkbox'
+ ],
+ [
+ 'id' => 'text_field',
+ 'name' => 'Text Field',
+ 'type' => 'text',
+ ],
+ ],
+ ]);
+
+ $data = [
+ 'status' => true,
+ 'integration_id' => 'email',
+ 'logic' => [
+ 'operatorIdentifier' => 'and',
+ 'children' => [
+ [
+ 'identifier' => 'checkbox_field',
+ 'value' => [
+ 'operator' => 'is_checked',
+ 'property_meta' => [
+ 'id' => 'checkbox_field',
+ 'type' => 'checkbox',
+ ]
+ ],
+ ],
+ ],
+ ],
+ 'settings' => [
+ 'send_to' => '[email protected]',
+ 'sender_name' => 'OpnForm',
+ 'subject' => 'New form submission with checkbox logic',
+ 'email_content' => 'Checkbox logic triggered.',
+ 'include_submission_data' => true,
+ 'include_hidden_fields_submission_data' => false,
+ 'reply_to' => null
+ ]
+ ];
+
+ $this->postJson(route('open.forms.integration.create', $form->id), $data)
+ ->assertSuccessful()
+ ->assertJson([
+ 'type' => 'success',
+ 'message' => 'Form Integration was created.'
+ ]);
+});