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

Form field attributes aren’t included in form schema #9124

Closed
kinglozzer opened this issue Jul 15, 2019 · 3 comments
Closed

Form field attributes aren’t included in form schema #9124

kinglozzer opened this issue Jul 15, 2019 · 3 comments

Comments

@kinglozzer
Copy link
Member

kinglozzer commented Jul 15, 2019

FormField::getSchemaDataDefaults() by default returns an empty array for the field’s attributes (third-last item in the below array):

public function getSchemaDataDefaults()
{
return [
'name' => $this->getName(),
'id' => $this->ID(),
'type' => $this->getInputType(),
'schemaType' => $this->getSchemaDataType(),
'component' => $this->getSchemaComponent(),
'holderId' => $this->HolderID(),
'title' => $this->obj('Title')->getSchemaValue(),
'source' => null,
'extraClass' => $this->extraClass(),
'description' => $this->obj('Description')->getSchemaValue(),
'rightTitle' => $this->obj('RightTitle')->getSchemaValue(),
'leftTitle' => $this->obj('LeftTitle')->getSchemaValue(),
'readOnly' => $this->isReadonly(),
'disabled' => $this->isDisabled(),
'customValidationMessage' => $this->getCustomValidationMessage(),
'validation' => $this->getSchemaValidation(),
'attributes' => [],
'autoFocus' => $this->isAutofocus(),
'data' => [],
];

I noticed this when adding a new field to GridFieldFilterHeader, any attributes I add to the field go missing as it’s built using the form schema. Workaround is to just use ->setSchemaData() to add the attributes manually

Changing it to 'attributes' => $this->getAttributes(), has the desired effect. Edit: that won’t work because recursion #9125 (comment)

PRs

Kitchen sink CI

@micschk
Copy link
Contributor

micschk commented Nov 24, 2021

Temporary workaround (eg for placeholder attribute):
$field->setSchemaData(['attributes' => ['placeholder' => 'My placeholder value']]);

@GuySartorelli
Copy link
Member

I think the way forward for this is in a major release call getAttributes() from getSchemaDataDefaults(), and make sure to update any core and supported modules to not call getSchemaData() in getAttributes() (e.g. TreeDropdownField - those data attributes should be added in the template directly instead, perhaps)

@emteknetnz
Copy link
Member

Linked PRs have been merged, they're be released with CMS 6.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants