Skip to content

Commit

Permalink
DOC Document including attributes in formfield schema data (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Nov 24, 2024
1 parent 8443b18 commit bac107e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions en/08_Changelogs/6.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ title: 6.0.0 (unreleased)
- [`DBDecimal` default value](#dbdecimal-default-value)
- [`RedirectorPage` validation](#redirectorpage-validation)
- [Update JS MIME type, remove `type` in `<script>` tags](#js-mime-type-update)
- [`getSchemaDataDefaults()` now includes attributes](#formfield-schema-data)
- [Full list of removed and changed API (by module, alphabetically)](#api-removed-and-changed)

## Features and enhancements
Expand Down Expand Up @@ -932,6 +933,28 @@ We've updated the MIME type for JavaScript from `"application/javascript"` to `"

This change is generally backward-compatible and should not affect existing functionality. However, if your project explicitly relies on the `type` attribute for `<script>` tags, you may need to adjust accordingly.

### `getSchemaDataDefaults()` now includes attributes {#formfield-schema-data}

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 include `$SchemaAttributesHtml` in your template 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 $SchemaAttributesHtml></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 bac107e

Please sign in to comment.