File tree Expand file tree Collapse file tree 4 files changed +65
-1
lines changed
apps/docs/src/content/docs/guides Expand file tree Collapse file tree 4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " docs " : patch
3+ ---
4+
5+ Add ` Programmatic control ` section
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import type { Schema } from " @sjsf/form" ;
3+
4+ import CustomForm from " @/components/custom-form.svelte" ;
5+
6+ const schema: Schema = {
7+ type: " string" ,
8+ };
9+
10+ let form = $state <HTMLFormElement >();
11+ </script >
12+
13+ <CustomForm bind:form {schema } novalidate onSubmit ={(v ) => window .alert (v )}>
14+ {null }
15+ </CustomForm >
16+
17+ <button
18+ onclick ={() => {
19+ form ?.requestSubmit ();
20+ }}>My submit</button
21+ >
22+
23+ <button onclick ={() => {
24+ form ?.reset ();
25+ }} >
26+ My reset
27+ </button >
Original file line number Diff line number Diff line change 11---
22title : Custom form
33sidebar :
4- order : 3
4+ order : 4
55---
66
77import { Code } from ' @astrojs/starlight/components' ;
Original file line number Diff line number Diff line change 1+ ---
2+ title : Programmatic control
3+ sidebar :
4+ order : 3
5+ ---
6+
7+ import { Code , Card } from ' @astrojs/starlight/components' ;
8+
9+ import BindForm from ' ./_bind-form.svelte' ;
10+ import bindFormCode from ' ./_bind-form.svelte?raw' ;
11+
12+ If you need to control the form programmatically, you can bind to the ` form ` property.
13+
14+ <Code code = { bindFormCode } lang = " svelte" />
15+
16+ <Card >
17+ <BindForm client :only = " svelte" />
18+ </Card >
19+
20+ ## Methods
21+
22+ Also you can bind to ` this ` to get access to exported methods:
23+
24+ ### Validate
25+
26+ Perform validation on the form without form state modifications.
27+
28+ ``` typescript
29+ import type { Errors } from ' @sjsf/form' ;
30+
31+ function validate(): Errors <E >
32+ ```
You can’t perform that action at this time.
0 commit comments