Skip to content

Commit 22f6c87

Browse files
committed
feat: update conditional wrapper documentation
1 parent 76cd8fd commit 22f6c87

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/basic-usage/conditional-wrapper.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,33 @@ In this example, we will disable the `max_salary` input field if the `any_max_sa
3434
<x-forms::number name="max_salary" label="Max Salary" />
3535

3636
<x-forms::checkbox name="any_max_salary" :value="1" data-toggle-checkbox="#max-salary" />
37+
```
38+
39+
## Enabling and disabling a section based on checkbox status
40+
You may want to show or hide parts of your UI depending on whether a checkbox is checked. The data-enable-section-checkbox attribute makes this easy to implement.
41+
42+
In the example below, sections are conditionally shown or hidden based on the status of the #existing_user checkbox.
43+
44+
```html
45+
46+
<x-forms::checkbox name="existing_user" :label="__('Existing Public User')" :value="1" :checked="true" inline />
47+
48+
<!-- This section is displayed only when the checkbox is checked -->
49+
<div data-enable-section-checkbox="#existing_user"
50+
data-hide-fields="true">
51+
<!-- Content visible when #existing_user is checked -->
52+
</div>
53+
54+
<!-- This section is hidden when the checkbox is checked -->
55+
<div data-enable-section-checkbox="#existing_user"
56+
data-hide-fields="true"
57+
data-disable="true">
58+
<!-- Content hidden when #existing_user is checked -->
59+
</div>
60+
```
61+
62+
**Attribute Explanation:**
63+
- `data-enable-section-checkbox`: Selector for the checkbox that controls the section.
64+
- `data-hide-fields="true"`: Hides all form fields within the section instead of removing the entire section.
65+
- `data-disable="true"`: Inverts the logic—disables or hides the section when the checkbox is checked.
66+

0 commit comments

Comments
 (0)