-
Notifications
You must be signed in to change notification settings - Fork 96
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
SPIKE Review option for handling cleared TreeTropDown validation #1616
Comments
To summarise a big discussion on #1578:
I've investigated this pretty deeply. I've created a pair of PRs that I think provide a fairly robust solution FormBuilder/redux-form is submitting null values because the default value of TreeDropdownfield inherits from FormField, which has a default value of null. Changing the default value of TreedropdownField to 0 makes this consistent with what happens if the TreedropField is in a page edit form, it means that it submits a "0" if left untouched. TreedropdownField only supports DataObjects that have the Hierarchy extension, and Hierarchy very much only works with relational data, rather than arbitary data, so it should have a default value of 0 which is the same as the default value of a RelationID. I count this a bugfix because the previous default value was incorrect, so we can release in a patch Despite this I still think we need to treat both blank string and 0 as empty values for both the frontend and serverside validation. This is because the proposed fixes need to go in both framework and admin modules and you can install one module with the fix and one without. I've fixed serverside validation with an update to RequiredFields.php adding in a condition for TreeDropdownField where it will treat both blank string and "0" as empty, so will fail validation I've fixed frontend validation with an update to Validator.js so that it's able to support passing in "extraEmptyValues" that are considered alongside empty string. Empty string should fail required fields validation is all scenarios. I've updated the TreeDropdownField to pass in a "0" for this. |
You can test TreeDropdownfield on a page and a FormBuilder form with LinkField 3.x-dev with the following code, assuming you've also installed linkfield <?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\LinkField\Form\LinkField;
use SilverStripe\LinkField\Models\Link;
class Page extends SiteTree
{
private static $db = [];
private static $has_one = [
'TestValidationPage' => SiteTree::class,
'MyLink' => Link::class,
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Main', [
TreeDropdownField::create('TestValidationPageID', null, SiteTree::class),
LinkField::create('MyLink'),
]);
return $fields;
}
public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create([
'TestValidationPageID',
]));
return $validator;
}
} And add the following to the bottom on SiteTreeLink.php (from the linkfield module, not the cms module) public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create('PageID'));
return $validator;
} |
I only read the description. Didn't look at the PR. Seems to make broad sense. My only question is around this.
Presumably, if we want to select the parent of a Page, In this framework, I'm assuming there's no distinction between, "I have not selected a value" and "I have put the page in the root". CMS 6If we think there's some follow up CMS6 work needed here, please create a card and stick it in the CMS6 milestone. |
If you wanted to have a
I think what you really mean is there's no distinction between "I have not selected a value" and "I have intentionally selected to empty the value of this field". And if the field was already defaulting to the empty value, then yes that's correct. Hierarchical records are in the root if they have no parent. This is by definition. I don't think it makes sense to change this, since having an item in the root while that item also has a parent would be contradictory. |
PRs are merged. Solution will be automatically tagged. |
Parent issue
#1576
Description
It's not clear to us what the "No value" value for a TreeDropdownField should be.
Identify a few alternative/approach and seek agreement from beloved colleagues.
Timebox
Half-day
Note
PRs
The text was updated successfully, but these errors were encountered: