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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user