feat: implement form submit button limit (#47)

* feat: implement form submit button limit

* feat: add submit control to form
This commit is contained in:
jmakhack 2022-10-06 10:07:02 -04:00 committed by GitHub
parent f1485808c9
commit 97128a0816
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -1,15 +1,18 @@
---
import type { FormGroup } from './core';
import type { FormControl, FormGroup } from './core';
import Field from './components/Field.astro';
import FieldSet from './components/FieldSet.astro';
export interface Props {
submitControl?: FormControl;
formGroups: FormGroup[];
}
const { formGroups } = Astro.props;
const { submitControl, formGroups } = Astro.props;
---
<form class="light">
{formGroups?.map((group) => <FieldSet group={group} />)}
{submitControl && (<Field control={submitControl} />)}
</form>
<style>

View file

@ -7,7 +7,9 @@ export class FormGroup {
constructor(controls: FormControlBase[], name = '') {
this.name = name;
this.controls = controls.map((control) => new FormControl(control));
this.controls = controls
.filter(control => control.type !== 'submit')
.map(control => new FormControl(control));
}
get(name: string): FormControl | undefined {