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 3, 2024
1 parent 2fcf68a commit ea5325a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1262,17 +1262,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

0 comments on commit ea5325a

Please sign in to comment.