Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Dynamically rendering form sections #1020

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion content/collections/tags/form-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ This way you can let Control Panel users select which form should be used on an

## Dynamic Rendering

### Dynamically Rendering Fields

Instead of hardcoding individual fields, you may loop through the `fields` array to render fields in a dynamic fashion.

```
Expand Down Expand Up @@ -154,7 +156,7 @@ Each item in the `fields` array contains the following data configurable in the
| `instructions` | string | User-friendly instructions label |
| `validate` | array | Contains an array of validation rules |

### Pre-rendered HTML
### Pre-rendered Field HTML

Using the `field` variable will intelligently render inputs as inputs, textareas as textareas, and snozzberries as snozzberries.

Expand Down Expand Up @@ -193,6 +195,30 @@ This approach, combined with the [blueprint editor](/blueprints), will give you
</form>
```

### Dynamically Rendering Sections

If you have defined multiple sections in your form's blueprint, you can loop over these `sections` in a dynamic fashion as well.

```
{{ sections }}
<fieldset>
<legend>{{ display }}</legend>
{{ fields }}
...
{{ /fields }}
</fieldset>
{{ /sections }}
```

Each item in the `sections` array contains the following data configurable in the form's blueprint.

| Variable | Type | Description |
|---|---| --- |
| `display` | string | User-friendly section label |
| `instructions` | string | User-friendly section instructions |
| `fields` | array | An array of [fields](#dynamically-rendering-fields) defined within that section |


## Conditional Fields 🆕

You may conditionally show and hide fields by utilizing the [conditional fields](/conditional-fields#overview) settings in your form's blueprint editor. Once configured, by including the necessary front-end scripts and enabling JavaScript on the `form:create` tag, all of the conditional logic will Just Work™.
Expand Down