# Fields Fields are the settings of a widget. Each field in `fields.json` becomes a control in the editor's settings, and its value can be used in the HTML, CSS and JS. The values are kept in `data.json`. ## Fields JSON `fields.json` is an object: each key is a field's name, each value describes the field. ```json { "title": { "type": "text", "label": "Title", "value": "New follower!", "group": "Texts" }, "fontSize": { "type": "slider", "label": "Font size (px)", "value": 32, "min": 16, "max": 72, "step": 1, "group": "Style" } } ``` | Property | For | Meaning | |---|---|---| | `type` | all | The control, see below. Required. | | `label` | all | Its label. The field's name when missing. | | `value` | all | The default value. For a button: the value sent with its event. | | `group` | all | Fields with the same group are shown in one collapsible section. | | `options` | `dropdown` | `{ "value": "Label", … }` | | `min`, `max`, `step` | `number`, `slider` | Limits of the value. | | `multiple` | `image-input`, `video-input`, `sound-input` | Several files: the value becomes a list. | A field name has 1-64 letters, digits, `_` or `-`, and does not start with a digit. `__proto__`, `constructor` and `prototype` are not allowed. ## Types | `type` | Control | Value | |---|---|---| | `text` | One line of text | text | | `textarea` | Several lines of text | text | | `number` | Number box | number (`""` when emptied) | | `slider` | Slider | number | | `checkbox` | Switch | `true` or `false` | | `colorpicker` | Color picker with transparency | text, e.g. `"#9147ff"` or `"rgba(20, 20, 28, 0.85)"` | | `dropdown` | Select box | the key of the chosen option (text) | | `googleFont` | Font picker | a font's name, e.g. `"Poppins"` | | `image-input` | Image from your media | the image's URL (`""` when none) | | `video-input` | Video from your media | the video's URL | | `sound-input` | Sound from your media | the sound's URL | | `button` | Button | none, see below | | `hidden` | Not shown | anything; use it for constants | An unknown type is shown as `text`. **Fonts.** A font chosen in a `googleFont` field is loaded for you from Google Fonts, in all weights. Use it in CSS as `font-family: '{{fontName}}', sans-serif;`. The picker also offers fonts every computer has. **Media.** Media fields store which file of your media gallery was picked; the widget receives its full URL. With `"multiple": true` the value is a list of URLs. ### Button A `button` field shows a button in the settings. Clicking it fires `onEventReceived` with the listener `widget-button` in every open copy of the widget (the preview and OBS): ```js window.addEventListener('onEventReceived', (obj) => { const { listener, event } = obj.detail; if (listener === 'widget-button' && event.field === 'testAlert') { // event.value is the button field's "value" showAlert({ type: 'follower', name: 'TestUser' }); } }); ``` ## Data JSON `data.json` holds the values set in the editor: `{ "fieldName": value, … }`. A value in Data overrides the field's default `value`. You rarely edit it by hand: the settings controls write it. Values are text, numbers, `true`/`false`, `null`, or lists of those. The value a widget gets for a field (its "field data") is: the value in Data, else the field's `value`, else nothing. ## Using values ### In HTML, CSS and JS: placeholders `{{fieldName}}` (or `{fieldName}`) is replaced with the field's value before the widget loads, in all three. Spaces are allowed only inside double braces: `{{ fieldName }}` is replaced, `{ fieldName }` is not. A list becomes its items joined with `,`. A placeholder whose name is not a field stays as it is. ```html