Skip to content

Commit 337d3d7

Browse files
committed
[docs] Add Programmatic control section
1 parent 12ef6f1 commit 337d3d7

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"docs": patch
3+
---
4+
5+
Add `Programmatic control` section
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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>

apps/docs/src/content/docs/guides/custom-form.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Custom form
33
sidebar:
4-
order: 3
4+
order: 4
55
---
66

77
import { Code } from '@astrojs/starlight/components';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
```

0 commit comments

Comments
 (0)