Skip to content

Commit

Permalink
ENH Call validate on form fields within form
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 11, 2024
1 parent a4028d0 commit 84e6524
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 13 additions & 4 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1264,17 +1264,26 @@ public function getLegend()
*/
public function validationResult()
{
$result = ValidationResult::create();

// Automatically pass if there is no validator, or the clicked button is exempt
// Note: Soft support here for validation with absent request handler
$handler = $this->getRequestHandler();
$action = $handler ? $handler->buttonClicked() : null;
$validator = $this->getValidator();
if (!$validator || $this->actionIsValidationExempt($action)) {
return ValidationResult::create();
if ($this->actionIsValidationExempt($action)) {
return $result;
}

// Invoke FormField validation
foreach ($this->Fields() as $field) {
$result->combineAnd($field->validate());
}

// Invoke validator
$result = $validator->validate();
$validator = $this->getValidator();
if ($validator) {
$result->combineAnd($validator->validate());
}
$this->loadMessagesFrom($result);
return $result;
}
Expand Down
6 changes: 0 additions & 6 deletions src/Forms/Validation/RequiredFieldsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ public function php($data)
$valid = true;
$fields = $this->form->Fields();

foreach ($fields as $field) {
$result = $field->validate();
$valid = $result->isValid() && $valid;
$this->result->combineAnd($result);
}

if (!$this->required) {
return $valid;
}
Expand Down

0 comments on commit 84e6524

Please sign in to comment.