Fix logic on hidden, loading on edit submission (#75)
This commit is contained in:
@@ -23,6 +23,11 @@ class FormLogicPropertyResolver
|
||||
return (new self($property, $values))->shouldBeRequired();
|
||||
}
|
||||
|
||||
public static function isHidden(array $property, array $values): bool
|
||||
{
|
||||
return (new self($property, $values))->shouldBeHidden();
|
||||
}
|
||||
|
||||
public function shouldBeRequired(): bool
|
||||
{
|
||||
if(!isset($this->property['required'])){
|
||||
@@ -42,4 +47,24 @@ class FormLogicPropertyResolver
|
||||
return $this->property['required'];
|
||||
}
|
||||
}
|
||||
|
||||
public function shouldBeHidden(): bool
|
||||
{
|
||||
if (! isset($this->property['hidden'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->logic) {
|
||||
return $this->property['hidden'];
|
||||
}
|
||||
|
||||
$conditionsMet = FormLogicConditionChecker::conditionsMet($this->logic['conditions'], $this->formData);
|
||||
if ($conditionsMet && $this->property['hidden'] && count($this->logic['actions']) > 0 && in_array('show-block', $this->logic['actions'])) {
|
||||
return false;
|
||||
} elseif ($conditionsMet && !$this->property['hidden'] && count($this->logic['actions']) > 0 && in_array('hide-block', $this->logic['actions'])) {
|
||||
return true;
|
||||
} else {
|
||||
return $this->property['hidden'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user