Skip to content

Commit

Permalink
revert previous change. only validate will add errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK committed Oct 7, 2020
1 parent 28e6a0b commit 79393a9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/DataHandlers/AbstractDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public function setValue($value)

public function validate(): array
{
$this->validateValue($this->getValue());
$this->clearErrors();
$errors = $this->validateValue($this->getValue());
$this->addError(...$errors);
return $this->getErrors();
}

Expand Down Expand Up @@ -210,7 +212,6 @@ public function validateValue($value, array $data = []): array
$errors = array_merge($errors, $validatorErrors);
}
}
$this->clearErrors()->addError(...$errors);
return $errors;
}

Expand Down
11 changes: 3 additions & 8 deletions src/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,10 @@ public function __isset($name)
}

/**
* @param bool $revalidate
*
* @return bool
*/
public function isValid(bool $revalidate = true): bool
public function isValid(): bool
{
if(!$revalidate)
{
return empty($handlerErrors);
}

foreach($this->_dataHandlers as $name => $handler)
{
$handlerErrors = $handler->validateValue($handler->getValue(), $this->getFormData());
Expand All @@ -124,9 +117,11 @@ public function validate(): array
$keyedErrors = [];
foreach($this->_dataHandlers as $name => $handler)
{
$handler->clearErrors();
$handlerErrors = $handler->validateValue($handler->getValue(), $this->getFormData());
if($handlerErrors)
{
$handler->addError(...$handlerErrors);
$keyedErrors[$name] = $handlerErrors;
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function testProperties()
$this->assertTrue($form->isValid());

$form->number->setValue('a');
$this->assertTrue($form->isValid(false));
$this->assertFalse($form->isValid());

$errors = $form->validate();
Expand Down

0 comments on commit 79393a9

Please sign in to comment.