Skip to content

Commit 960255d

Browse files
authored
Document button field
Documents wintercms/winter#1324
1 parent b7ddaf3 commit 960255d

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

backend/forms.md

+70
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,76 @@ gender:
303303

304304
See [Defining field options](#defining-field-options) for the different methods to specify the options.
305305

306+
### Button
307+
308+
`button` - renders a single [button](../../ui/controls/button). Supports triggering an [AJAX request](../ajax/introduction), acting as a link to a URL, or [opening a popup](../../ui/controls/popup#remote-popups).
309+
310+
The `action` of the button (`button`, `link`, or `popup`) is determined by the configuration of the button. If the value of the field is a valid URL, or the `href` property is set, then it will be a `link` action. If a `handler` property is set, it will be a `popup` action. All other cases will result in the `button` action.
311+
312+
```yaml
313+
button:
314+
type: button
315+
buttonLabel: # The label of the button itself.
316+
buttonType: # default | primary | success | info | warning | danger | link
317+
path: # Use a custom partial to render the button
318+
handler: # popup action only
319+
href: # link action only
320+
target: # link action only
321+
request: # button action only
322+
loading: # message to display while waiting for the request
323+
icon: 'icon-pencil'
324+
```
325+
326+
The partial used to render the partial can be manually specified by providing the `path` property, the same as a [`partial`](#partial) field. This partial will receive the same variables as a regular `partial` field, with the addition of the following variables:
327+
328+
Variable | Description
329+
------------- | -------------
330+
`$action` | The action of the button. One of `button`, `link`, `popup`.
331+
`$element` | The HTML element recommended to use for the button. Either `a` or `button`.
332+
`$label` | The label of the button itself.
333+
`$buttonType` | The type of button to render. One of `default`, `primary`, `success`, `info`, `warning`, `danger`, `link`.
334+
`$classes` | The CSS classes that should be applied to the button element.
335+
`$handler` | The popup AJAX handler.
336+
`$request` | The AJAX request to send when the button is clicked.
337+
`$href` | The URL to link to for a `link` action button.
338+
`$target` | The `target` attribute for the `link` action button.
339+
`$loading` | The loading message to display when the button has been clicked. Populates the `data-load-indicator` attribute on the button element.
340+
`$icon` | The [icon class](../../ui/style/icon) to use for the icon element inside the button.
341+
342+
#### Examples:
343+
344+
Simple button with AJAX request:
345+
```yaml
346+
_sync_ics:
347+
label: Actions
348+
buttonLabel: Sync
349+
type: button
350+
request: onSyncICS
351+
icon: 'icon-rotate'
352+
loading: Syncing...
353+
```
354+
355+
Simple Link button:
356+
```yaml
357+
places_url:
358+
type: button
359+
buttonType: primary
360+
buttonLabel: View on Google Maps
361+
icon: icon-map-location-dot
362+
target: _blank
363+
```
364+
365+
Button triggering popup:
366+
```yaml
367+
_btn_autofill:
368+
label: Autofill
369+
buttonLabel: Autofill Club Information
370+
type: button
371+
handler: onRenderAutofillPopup
372+
buttonType: primary
373+
icon: icon-map-location-dot
374+
```
375+
306376
### Checkbox
307377

308378
`checkbox` - renders a single checkbox.

0 commit comments

Comments
 (0)