Skip to content

Commit a2f147d

Browse files
committed
feat: update to match 3.13
1 parent 5cd8057 commit a2f147d

File tree

4 files changed

+140
-2
lines changed

4 files changed

+140
-2
lines changed

src/content/docs/guides/forms/getting-started.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default defineConfig({
6666
});
6767
```
6868

69-
This integration will simplify your debugging process by eliminating the browser pop-ups during every Vite reload
69+
This integration change the way Astro handle the render - will render in the order it was written, to allow the forms to work properly.
7070

7171
Edit
7272
`src/middleware.ts` to add the middleware

src/content/docs/reference/forms/components.md renamed to src/content/docs/reference/forms/basic-form-components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Components
2+
title: Basic Form Components
33
description: HTML like form for Astro
44
---
55

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Client Side Events & Triggers
3+
description: Forms client side events & submit triggers
4+
---
5+
6+
## Client Side Events
7+
8+
You can listen to submit events to handle the loading while the form is being submitted.
9+
10+
```ts
11+
type SubmitInfo = {
12+
button: HTMLButtonElement,
13+
uploads: {count: number, totalSize: number} // only for big files
14+
};
15+
16+
document.addEventListener('WFSubmitting', ({detail}: {details: SubmitInfo}) => {
17+
const {button, uploads} = details;
18+
19+
button.classList.add('loading');
20+
console.log('Form is being submitted');
21+
});
22+
```
23+
24+
## Submit Triggers
25+
26+
If you want custom event to submit the form, you can use the `submitForm` global function.
27+
28+
```astro
29+
---
30+
import { Bind, BButton, BindForm } from '@astro-utils/forms/forms.js';
31+
32+
const form = Bind();
33+
34+
function onSubmit(){
35+
console.log(form.select);
36+
}
37+
---
38+
<BindForm bind={form}>
39+
<BSelect name="select" required onchange="submitForm(this)">
40+
<BOption value="1">Option 1</BOption>
41+
<BOption value="2">Option 2</BOption>
42+
</BSelect>
43+
44+
<BButton onClick={onSubmit} class="hidden">This button is hidden</BButton>
45+
</BindForm>
46+
```
47+
48+
49+
### Select button
50+
It will try to select the best BButton in this BindForm.
51+
52+
The order of selection is:
53+
1. The last BButton with the `whenFormOK` attribute.
54+
2. Last BButton in the form.
55+
56+
You can also manually configure that by adding the `data-submit` attribute to the select.
57+
58+
```astro
59+
<BSelect name="select" required onchange="submitForm(this)" data-submit="consoleItButton">
60+
<BOption value="1">Option 1</BOption>
61+
<BOption value="2">Option 2</BOption>
62+
</BSelect>
63+
64+
<BButton id="consoleItButton" onClick={onSubmit} class="hidden">This button is hidden</BButton>
65+
```
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Upload Big File Component
3+
description: Uploading Big Files with Astro Utils
4+
---
5+
6+
## Big File Upload
7+
8+
The big file upload component is a simple way to upload large files to the server. It uses the `xhr` API to upload the file in chunks (and not all at once). This way, the server can handle large files without running out of memory.
9+
10+
It is also able to show the progress of the upload and handle errors (in the server side).
11+
12+
## Components
13+
14+
### UploadBigFile
15+
16+
Same as the `BInput` component, but for big files.
17+
18+
```astro
19+
---
20+
import { BigFile, Bind, FormErrors, BButton } from '@astro-utils/forms/forms.js';
21+
22+
type Form = {
23+
file: BigFile
24+
showSubmitText: string;
25+
}
26+
27+
const bind = Bind<Form>();
28+
function formSubmit(){
29+
showSubmitText = `You uploaded ${form.file.name} (${form.file.size} bytes)`;
30+
}
31+
---
32+
<BindForm bind={bind}>
33+
<FormErrors />
34+
<p>{showSubmitText}</p>
35+
<UploadBigFile name="file" required/>
36+
37+
<BButton onClick={formSubmit} whenFormOK>Submit</BButton>
38+
</BindForm>
39+
```
40+
41+
### UploadBigFileProgress
42+
43+
A progress bar connected to a `UploadBigFile` component.
44+
45+
```astro
46+
<UploadBigFile name="file" required/>
47+
<UploadBigFileProgress for="file" />
48+
```
49+
50+
## Configuration
51+
52+
All configuration is done through the middleware. The following options are available:
53+
54+
```ts
55+
type MiddlewareOptions = {
56+
forms?: {
57+
bigFilesUpload?: {
58+
bigFileClientOptions?: {
59+
retryChunks?: number; // default: 5
60+
chunkSize?: number; // default: 5MB
61+
parallelChunks?: number; // default: 3
62+
parallelUploads?: number; // default: 3
63+
},
64+
bigFileServerOptions?: {
65+
maxUploadTime?: number; // default: 1.5 hours
66+
maxUploadSize?: number; // default: 1GB
67+
maxDirectorySize?: number; // default: 50GB
68+
tempDirectory?: string; // default: path.join(os.tmpdir(), "astro_forms_big_files_uploads")
69+
};
70+
}
71+
}
72+
}
73+
```

0 commit comments

Comments
 (0)