Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Call validate on form fields within form #11496

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 0 additions & 6 deletions src/Forms/RequiredFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,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
Loading