Skip to content

Commit

Permalink
DOC Document including attributes in formfield schema data
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 15, 2024
1 parent 9a14443 commit 54b6483
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions en/08_Changelogs/6.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,28 @@ Previously if an invalid default value was provided for a [`DBDecimal`](api:Silv

[`RedirectorPage`](api:SilverStripe\CMS\Model\RedirectorPage) now uses the [`Url` constraint](https://symfony.com/doc/current/reference/constraints/Url.html) from `symfony/validator` to validate the `ExternalURL` field. It will no longer add `http://` to the start of URLs for you if you're missing a protocol - instead, a validation error message will be displayed.

### `getSchemaDataDefaults()` now includes attributes

The [`FormField::getSchemaDataDefaults()`](api:SilverStripe\Forms\FormField::getSchemaDataDefaults()) method (and by extension the [`getSchemaData()`](api:SilverStripe\Forms\FormField::getSchemaData()) method) now calls [`getAttributes()`](api:SilverStripe\Forms\FormField::getAttributes()). This was done so that attributes such as `placeholder` can be used in the react components that render form fields.

In the past it was common to call `getSchemaData()` inside the `getAttributes()` method, so that a form field rendered in an entwine admin context had the data necessary to bootstrap a react component for that field. Doing that now would result in an infinite recursion loop.

If you were calling `getSchemaData()` in your `getAttributes()` method in a `FormField` subclass, we recommend you include the schema data in the template directly instead. For example:

```diff
-public function getAttributes()
-{
- $attributes = parent::getAttributes();
- $attributes['data-schema'] = json_encode($this->getSchemaData());
- return $attributes;
-}
```

```diff
-<div $AttributesHTML></div>
+<div $AttributesHTML data-schema="$SchemaData.JSON"></div>
```

### Full list of removed and changed API (by module, alphabetically) {#api-removed-and-changed}

<!--- Changes below this line will be automatically regenerated -->
Expand Down

0 comments on commit 54b6483

Please sign in to comment.