You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/frontend/custom-ui/custom-card.md
+73Lines changed: 73 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -319,3 +319,76 @@ window.customCards.push({
319
319
"https://developers.home-assistant.io/docs/frontend/custom-ui/custom-card", // Adds a help link in the frontend card editor
320
320
});
321
321
```
322
+
323
+
### Using the built-in form editor
324
+
While one way to configure a graphical editor is to supply a custom editor element, another option for cards with relatively simple configuration requirements is to use the built-in frontend form editor. This is done by defining a static `getConfigForm` function in your card class, that returns a form schema defining the shape of your configuration form.
if (schema.name === "icon") return "Special Icon";
364
+
return undefined;
365
+
},
366
+
computeHelper: (schema) => {
367
+
switch (schema.name) {
368
+
case "entity":
369
+
return "This text describes the function of the entity selector";
370
+
case "unit":
371
+
return "The unit of measurement for this card";
372
+
}
373
+
return undefined;
374
+
},
375
+
assertConfig: (config) => {
376
+
if (config.other_option) {
377
+
throw new Error("'other_option' is unexpected.");
378
+
}
379
+
},
380
+
};
381
+
}
382
+
```
383
+
From this function, you should return an object with up to 4 keys:
384
+
385
+
- `schema` _(required)_: This is a list of schema objects, one per form field, defining various properties of the field, like the name and selector.
386
+
- `computeLabel` _(optional)_: This callback function will be called per form field, allowing the card to define the label that will be displayed for the field. If `undefined`, Home Assistant may apply a known translation for generic field names like `entity`, or you can supply your own translations.
387
+
- `computeHelper` _(optional)_: This callback function will be called per form field, allowing you to define longer helper text for the field, which will be displayed below the field.
388
+
- `assertConfig` _(optional)_: On each update of the configuration, the user's config will be passed to this callback function. If you throw an `Error` during this callback, the visual editor will be disabled. This can be used to disable the visual editor when the user enters incompatible data, like entering an object in yaml for a selector that expects a string. If a subsequent execution of this callback does not throw an error, the visual editor will be re-enabled.
389
+
390
+
This example then results in the following config form:
391
+

0 commit comments