Skip to content

Commit

Permalink
fix(files): parse multi file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto committed Aug 16, 2024
1 parent 6796d99 commit 0a5c0db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions examples/simple-form/src/pages/multi-file-upload.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
import Layout from '../layouts/Layout.astro';
import {BButton, Bind, BindForm, BInput, FormErrors} from '@astro-utils/forms/forms.js';
import {Button} from 'reactstrap';
import 'bootstrap/dist/css/bootstrap.css';
type Form = {
files: File[];
}
const form = Bind<Form>();
let showSubmitText: string;
function formSubmit() {
showSubmitText = `You upload "${form.files.map(file => file.name).join(', ')}"`;
}
---
<Layout title="Upload file">
<BindForm bind={form}>
<FormErrors/>
{showSubmitText}

<h4>File to upload*</h4>
<BInput type="file" name="files" multiple/>

<BButton as={Button} props={{color: 'success'}} onClick={formSubmit} whenFormOK>Submit</BButton>
</BindForm>
</Layout>
4 changes: 2 additions & 2 deletions packages/forms/src/components-control/form-utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ async function isBigFile(value: string) {
export async function parseFiles(about: AboutFormName, astro: AstroGlobal, multiple: boolean, readonly: boolean) {
if (readonly) return;

const { disposeFiles } = getContext(astro, '@astro-utils/forms');
const { disposeFiles, bindId = '' } = getContext(astro, '@astro-utils/forms');
let values = [about.formValue];

let hasFailed = false;
if (multiple) {
values = about.formValue = await getFormMultiValue(astro.request, about.originalName);
values = about.formValue = await getFormMultiValue(astro.request, bindId + about.originalName);

const promises: Promise<any>[] = [];
for (let i = 0; i < values.length; i++) {
Expand Down

0 comments on commit 0a5c0db

Please sign in to comment.