Skip to content

Commit

Permalink
ENH Use FieldValidator for FormFields
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 31, 2024
1 parent ea084d0 commit a748820
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion code/Form/UserFormsRequiredFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function php($data)
$fields = $this->form->Fields();

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

if (empty($this->required)) {
Expand Down
15 changes: 4 additions & 11 deletions code/FormField/UserFormsCheckboxSetField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace SilverStripe\UserForms\FormField;

use SilverStripe\Core\Validation\ValidationResult;
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\UserForms\Model\EditableFormField;

/**
* @package userforms
Expand Down Expand Up @@ -45,14 +45,7 @@ public function getOptions()
return $options;
}

/**
* @inheritdoc
*
* @param Validator $validator
*
* @return bool
*/
public function validate($validator)
public function validate(): ValidationResult
{
// get the previous values (could contain comma-delimited list)

Expand All @@ -66,12 +59,12 @@ public function validate($validator)

$this->setValue($value);

$validated = parent::validate($validator);
$result = parent::validate();

// restore previous value after validation

$this->setValue($previous);

return $validated;
return $result;
}
}

0 comments on commit a748820

Please sign in to comment.