diff --git a/client/src/legacy/ElementEditor/entwine.js b/client/src/legacy/ElementEditor/entwine.js index 91123572..5154d05f 100644 --- a/client/src/legacy/ElementEditor/entwine.js +++ b/client/src/legacy/ElementEditor/entwine.js @@ -44,7 +44,7 @@ jQuery.entwine('ss', ($) => { AreaIDsSharedObject: {}, // Increment is in Element.js to force subsequent form submissions on failed client-side validation - // If elements fail client-side validation in Validator.js e.g. RequiredFields then + // If elements fail client-side validation in Validator.js e.g. RequiredFieldsValidator then // they'll end up in a state where they need to re-render in order to re-submit // because the form submission is blocked by the client-side validation, meaning that // no formSchema response is received which is normally used to trigger a state update diff --git a/docs/en/02_advanced_setup.md b/docs/en/02_advanced_setup.md index e20128bd..c1e34655 100644 --- a/docs/en/02_advanced_setup.md +++ b/docs/en/02_advanced_setup.md @@ -189,15 +189,15 @@ class BlockPage extends Page Custom elemental blocks can have validation set using standard [model validation](https://docs.silverstripe.org/en/developer_guides/model/validation/#model-validation). -For example to make ensure your elemental block has populated its `has_one` relation using a `RequiredFields` validator, and validate the value of a field: +For example to make ensure your elemental block has populated its `has_one` relation using a `RequiredFieldsValidator` validator, and validate the value of a field: ```php namespace App\Model; use DNADesign\Elemental\Models\BaseElement; use SilverStripe\Assets\File; -use SilverStripe\Forms\CompositeValidator; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\CompositeValidator; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; class MyBlock extends BaseElement { @@ -212,7 +212,7 @@ class MyBlock extends BaseElement public function getCMSCompositeValidator(): CompositeValidator { $validator = parent::getCMSCompositeValidator(); - $validator->addValidator(RequiredFields::create(['MyFile'])); + $validator->addValidator(RequiredFieldsValidator::create(['MyFile'])); return $validator; } diff --git a/src/Forms/EditFormFactory.php b/src/Forms/EditFormFactory.php index 328ad7b7..397f8591 100644 --- a/src/Forms/EditFormFactory.php +++ b/src/Forms/EditFormFactory.php @@ -9,8 +9,8 @@ use SilverStripe\Forms\FieldList; use SilverStripe\Forms\HTMLEditor\HTMLEditorField; use SilverStripe\ORM\DataObject; -use SilverStripe\Forms\RequiredFields; -use SilverStripe\Forms\CompositeValidator; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; +use SilverStripe\Forms\Validation\CompositeValidator; class EditFormFactory extends DefaultFormFactory { @@ -66,11 +66,11 @@ protected function getFormValidator(?RequestHandler $controller, $name, $context return null; } $id = $context['Record']->ID; - foreach ($compositeValidator->getValidatorsByType(RequiredFields::class) as $validator) { + foreach ($compositeValidator->getValidatorsByType(RequiredFieldsValidator::class) as $validator) { $requiredFields = $validator->getRequired(); foreach ($requiredFields as $requiredField) { // Add more required fields with appendend field prefixes - // this is done so that front end validation works, at least for RequiredFields + // this is done so that front end validation works, at least for RequiredFieldsValidator // you'll end up with two sets of required fields: // - Title -- used for backend validation when inline saving an element // - PageElements__Title -- used for frontend js validation onchange() diff --git a/tests/Behat/features/non-inline-block-validation.feature b/tests/Behat/features/non-inline-block-validation.feature index b198642e..fdc9da0b 100644 --- a/tests/Behat/features/non-inline-block-validation.feature +++ b/tests/Behat/features/non-inline-block-validation.feature @@ -20,20 +20,20 @@ Feature: Blocks are validated when non-inline saving blocks Scenario: Non-inline block validation - # Related has_one RequiredFields with ID suffix (MyPageID) + # Related has_one RequiredFieldsValidator with ID suffix (MyPageID) When I press the "Save" button Then I should see "\"My page\" is required" in the "#message-Form_ItemEditForm_MyPageID" element And I click on the "#Form_ItemEditForm_MyPageID" element And I click on the ".ss-searchable-dropdown-field__option:nth-of-type(2)" element - # Related has_one RequiredFields without ID suffix (MyFile) + # Related has_one RequiredFieldsValidator without ID suffix (MyFile) Then I should see "\"My file\" is required" in the "#message-Form_ItemEditForm_MyFile" element When I click "Choose existing" in the ".uploadfield" element And I press the "Back" HTML field button And I click on the file named "file1" in the gallery And I press the "Insert" button - # RequiredFields on TextCheckboxGroupField (composite) field + # RequiredFieldsValidator on TextCheckboxGroupField (composite) field When I fill in "Title" with "" And I press the "Save" button Then I should see "\"Title\" is required" in the "#message-Form_ItemEditForm_Title" element diff --git a/tests/Behat/features/non-page-save-validation.feature b/tests/Behat/features/non-page-save-validation.feature index b7d6982a..72a53df7 100644 --- a/tests/Behat/features/non-page-save-validation.feature +++ b/tests/Behat/features/non-page-save-validation.feature @@ -16,7 +16,7 @@ Feature: Blocks are validated when saving blocks on a non-page dataobject And I click "Blocks Object" in the ".ss-gridfield-items" element Scenario: Validation when parent saving inline blocks - # ElementalArea 1 - Blank title - RequiredFields + # ElementalArea 1 - Blank title - RequiredFieldsValidator # Click "Add element" button And I click on the "#Form_ItemEditForm_ElementalArea1 .element-editor__toolbar button" element # Select ElementContent block type @@ -52,7 +52,7 @@ Feature: Blocks are validated when saving blocks on a non-page dataobject And I click on the caret button for block 2 # Save the parent Object - # Check that that client side validation for RequiredFields has been disabled + # Check that that client side validation for RequiredFieldsValidator has been disabled # and that an error response triggers a single validation error toast When I press the "Save" button When I click on the ".toast__close" element @@ -75,7 +75,7 @@ Feature: Blocks are validated when saving blocks on a non-page dataobject When I click on the ".toast__close" element Then I should not see a ".toast__close" element - # Provide a valid value for the RequiredFields test + # Provide a valid value for the RequiredFieldsValidator test # The parent object will save after this is resolved When I scroll to the top of the edit form panel And I fill in "Valid block one" for "Title" for block 1 diff --git a/tests/Behat/features/page-save-validation.feature b/tests/Behat/features/page-save-validation.feature index ff74381e..5b9c730e 100644 --- a/tests/Behat/features/page-save-validation.feature +++ b/tests/Behat/features/page-save-validation.feature @@ -18,7 +18,7 @@ Feature: Blocks are validated when page saving blocks Scenario: Validation when page saving inline blocks - # ElementalArea 1 - Blank title - RequiredFields + # ElementalArea 1 - Blank title - RequiredFieldsValidator # Click "Add element" button And I click on the "#Form_EditForm_ElementalArea1 .element-editor__toolbar button" element # Select ElementContent block type @@ -54,7 +54,7 @@ Feature: Blocks are validated when page saving blocks And I click on the caret button for block 2 # Save the page - # Check that that client side validation for RequiredFields has been disabled + # Check that that client side validation for RequiredFieldsValidator has been disabled # and that an error response triggers a single validation error toast When I press the "Save" button When I click on the ".toast__close" element @@ -77,7 +77,7 @@ Feature: Blocks are validated when page saving blocks When I click on the ".toast__close" element Then I should not see a ".toast__close" element - # Provide a valid value for the RequiredFields test + # Provide a valid value for the RequiredFieldsValidator test # The page will save after this is resolved When I scroll to the top of the edit form panel And I fill in "Valid block one" for "Title" for block 1 diff --git a/tests/Blocks/TestElementContent.php b/tests/Blocks/TestElementContent.php index 643f3f2c..f05c6c1f 100644 --- a/tests/Blocks/TestElementContent.php +++ b/tests/Blocks/TestElementContent.php @@ -4,9 +4,9 @@ use SilverStripe\Dev\TestOnly; use DNADesign\Elemental\Models\ElementContent; -use SilverStripe\Forms\CompositeValidator; +use SilverStripe\Forms\Validation\CompositeValidator; use SilverStripe\Core\Validation\ValidationResult; -use SilverStripe\Forms\Validator; +use SilverStripe\Forms\Validation\Validator; class TestElementContent extends ElementContent implements TestOnly {