Skip to content

Commit

Permalink
API Rename validator classes
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 2, 2024
1 parent 3107e55 commit a1ff04a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client/src/legacy/ElementEditor/entwine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/en/02_advanced_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\RequiredFieldsValidator;

class MyBlock extends BaseElement
{
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Forms/EditFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\CompositeValidator;

class EditFormFactory extends DefaultFormFactory
Expand Down Expand Up @@ -66,11 +66,11 @@ protected function getFormValidator(RequestHandler $controller = null, $name, $c
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_<ElementID>_Title -- used for frontend js validation onchange()
Expand Down
6 changes: 3 additions & 3 deletions tests/Behat/features/non-inline-block-validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/Behat/features/non-page-save-validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/Behat/features/page-save-validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a1ff04a

Please sign in to comment.