
* chore: updates for new validator package and landing-page app * docs: update packages examples * chore: bump patch, update docs
2.9 KiB
2.9 KiB
Astro Reactive Form
Generate a dynamic form based on your data, and modify programatically.
Installation
In your Astro project:
npm i @astro-reactive/form
Usage
Use in an Astro page:
---
import Form, { FormControl, FormGroup } from "@astro-reactive/form";
// create a form group
const form = new FormGroup([
{
name: "username",
label: "Username",
},
{
name: "password",
label: "Password",
type: "password",
},
]);
// set the name optionally
form.name = "Simple Form";
// you can insert a control at any point
form.controls.push(
new FormControl({
type: "checkbox",
name: "is-awesome",
label: "is Awesome?",
labelPosition: "right",
})
);
// you can get a FormControl object
const userNameControl = form.get("username");
// you can set values dynamically
userNameControl?.setValue("RAMOOOON");
form.get('is-awesome')?.setValue("checked");
---
<!--
the `formGroups` attribute can take a single FormGroup
or an array of FormGroup for multiple fieldsets;
we do a single for now in this example
-->
<Form
formGroups={form}
submitControl={{
type: "submit",
name: "submit",
}}
/>
Screenshots
Result of example above:
Example of multiple form groups:
Validation
See our package for setting up validators.
Future Plans
Currently this only supports very basic form creation, but the goal of the project is ambitious:
- Themes - unstyled, light mode, dark mode, compact, large
- FormGroup class
statusChanges
- observable that emits the form status when it changesvalueChanges
- observable that emits the values of all controls when they change
- FormControl class
statusChanges
- observable that emits the control status when it changesvalueChanges
- observable that emits the control value when it changes
- Documentation website
... and so much more
All contributions are welcome. Let's make the fastest web form component powered by Astro
Older Versions
Older versions can be found here.