Dc3e4 new matrix field (#484)
* fix password reset bug * wip: matrix input * wip: matrix input * wip: matrix input * Fixed matric input component logic * matrix input cleanup * fix lint errors * table border and radius * cleanup, linting * fix component methos * wip matrix input * matrix condition for contains and not contain * patch matrix input condition logic * linting * refactor and cleanup * fix syntax error * Polished the matrix input * Fix linting --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -72,6 +72,8 @@ class FormLogicConditionChecker
|
||||
return $this->multiSelectConditionMet($propertyCondition, $value);
|
||||
case 'files':
|
||||
return $this->filesConditionMet($propertyCondition, $value);
|
||||
case 'matrix':
|
||||
return $this->matrixConditionMet($propertyCondition, $value);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -90,6 +92,30 @@ class FormLogicConditionChecker
|
||||
return \Str::contains($fieldValue, $condition['value']);
|
||||
}
|
||||
|
||||
private function checkMatrixContains($condition, $fieldValue): bool
|
||||
{
|
||||
|
||||
foreach($condition['value'] as $key => $value) {
|
||||
if(!(array_key_exists($key, $condition['value']) && array_key_exists($key, $fieldValue))) {
|
||||
return false;
|
||||
}
|
||||
if($condition['value'][$key] == $fieldValue[$key]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkMatrixEquals($condition, $fieldValue): bool
|
||||
{
|
||||
foreach($condition['value'] as $key => $value) {
|
||||
if($condition['value'][$key] !== $fieldValue[$key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkListContains($condition, $fieldValue): bool
|
||||
{
|
||||
if (is_null($fieldValue)) {
|
||||
@@ -408,4 +434,20 @@ class FormLogicConditionChecker
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function matrixConditionMet(array $propertyCondition, $value): bool
|
||||
{
|
||||
switch ($propertyCondition['operator']) {
|
||||
case 'equals':
|
||||
return $this->checkMatrixEquals($propertyCondition, $value);
|
||||
case 'does_not_equal':
|
||||
return !$this->checkMatrixEquals($propertyCondition, $value);
|
||||
case 'contains':
|
||||
return $this->checkMatrixContains($propertyCondition, $value);
|
||||
case 'does_not_contain':
|
||||
return !$this->checkMatrixContains($propertyCondition, $value);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,17 @@ class FormSubmissionFormatter
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMatrixString(array $val): string
|
||||
{
|
||||
$parts = [];
|
||||
foreach ($val as $key => $value) {
|
||||
if ($key !== null && $value !== null) {
|
||||
$parts[] = "$key: $value";
|
||||
}
|
||||
}
|
||||
return implode(' | ', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a nice "FieldName": "Field Response" array
|
||||
* - If createLink enabled, returns html link for emails and links
|
||||
@@ -145,7 +156,9 @@ class FormSubmissionFormatter
|
||||
} else {
|
||||
$returnArray[$field['name']] = $val;
|
||||
}
|
||||
} elseif (in_array($field['type'], ['files', 'signature'])) {
|
||||
} elseif ($field['type'] == 'matrix' && is_array($data[$field['id']])) {
|
||||
$returnArray[$field['name']] = $this->getMatrixString($data[$field['id']]);
|
||||
} elseif ($field['type'] == 'files') {
|
||||
if ($this->outputStringsOnly) {
|
||||
$formId = $this->form->id;
|
||||
$returnArray[$field['name']] = implode(
|
||||
@@ -219,7 +232,9 @@ class FormSubmissionFormatter
|
||||
} else {
|
||||
$field['value'] = $val;
|
||||
}
|
||||
} elseif (in_array($field['type'], ['files', 'signature'])) {
|
||||
} elseif ($field['type'] == 'matrix') {
|
||||
$field['value'] = str_replace(' | ', "\n", $this->getMatrixString($data[$field['id']]));
|
||||
} elseif ($field['type'] == 'files') {
|
||||
if ($this->outputStringsOnly) {
|
||||
$formId = $this->form->id;
|
||||
$field['value'] = implode(
|
||||
|
||||
Reference in New Issue
Block a user