Skip to content

Commit 4a369c4

Browse files
committed
fix: onSubmitClick usage example
1 parent a2f147d commit 4a369c4

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/content/docs/reference/forms/events-and-triggers.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,40 @@ The order of selection is:
5353
1. The last BButton with the `whenFormOK` attribute.
5454
2. Last BButton in the form.
5555

56-
You can also manually configure that by adding the `data-submit` attribute to the select.
56+
You can also manually configure that by adding the `onSubmitClick` attribute to the select.
5757

5858
```astro
59-
<BSelect name="select" required onchange="submitForm(this)" data-submit="consoleItButton">
59+
<BSelect name="select" required onchange="submitForm(this)" onSubmitClick="consoleItButton">
6060
<BOption value="1">Option 1</BOption>
6161
<BOption value="2">Option 2</BOption>
6262
</BSelect>
6363
6464
<BButton id="consoleItButton" onClick={onSubmit} class="hidden">This button is hidden</BButton>
65-
```
65+
```
66+
67+
68+
### Search Input Example
69+
70+
Here's another example using a search input that triggers form submission:
71+
72+
```astro
73+
---
74+
import { Bind, BButton, BindForm, BInput } from '@astro-utils/forms/forms.js';
75+
76+
const form = Bind();
77+
78+
function onSearch(){
79+
console.log('Searching for:', form.searchQuery);
80+
}
81+
---
82+
<BindForm bind={form}>
83+
<BInput name="searchQuery" placeholder="Enter search term..." onSubmitClick="searchButton" />
84+
<BButton id="searchButton" onClick={onSearch}>Search</BButton>
85+
86+
<BButton onClick={() => {}} whenFormOK>No Search</BButton>
87+
</BindForm>
88+
```
89+
90+
This example shows how to:
91+
- Use a search input that submits on Enter key press
92+
- If we hav'nt used the 'onSubmitClick', it will default to the last button with 'whenFormOK' attribute

0 commit comments

Comments
 (0)