astro-reactive-form/packages/form
2025-01-08 14:19:04 +01:00
..
components feat(form): change validate on load to true by default (#284) 2023-03-25 09:47:46 +01:00
core feat(form): change validate on load to true by default (#284) 2023-03-25 09:47:46 +01:00
src chore: update astro to v2 (#269) 2023-03-16 22:39:47 +01:00
test feat(form): add form action for submit (#237) 2022-12-27 20:42:34 +01:00
.editorconfig feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
.eslintignore feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
.eslintrc.cjs feat: sharing config files (#253) 2023-01-11 19:09:35 +01:00
.prettierrc.cjs chore: update deps (#305) 2023-09-25 16:27:50 +02:00
CHANGELOG.md chore: Update version for release (#310) 2023-11-11 20:56:38 +01:00
index.ts refactor: form package cleanup (#135) 2022-10-23 23:04:40 +02:00
package.json chore: patch version 2025-01-08 14:19:04 +01:00
README.md chore: update docs site URL (#311) 2023-11-13 14:24:05 +01:00
tsconfig.json feat: sharing config files (#253) 2023-01-11 19:09:35 +01:00
vitest.config.ts chore: set up test:coverage scripts (#260) 2023-02-01 18:05:27 +01:00

Astro Reactive Library Logo
Astro Reactive Form
Generate a dynamic form based on your data, and modify programmatically.

Package information: NPM version Package information: NPM license Package information: NPM downloads Package information: NPM dependencies status

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",
  },
]);

// you can insert a control at any point
form.controls.push(
  new FormControl({
    type: "checkbox",
    name: "isAwesome",
    label: "is Awesome?",
  })
);

// set the value of multiple controls
form.setValue({
	username: 'DEFAULT',
	isAwesome: 'checked',
});

// you can get a FormControl object
const userNameControl = form.get("username");

// you can set the value of specific control
userNameControl?.setValue("RAMOOOON");

---

<Form
  formGroups={form}
  validateOnLoad
  showValidationHints
  action="/submission"
  method="post"
  submitControl={{
    name: 'submit',
    type: 'submit',
  }}
/>

👉 For more examples and explanations of the component properties, see the Form API Docs.

Screenshots

Result of example above:

Screen Shot 2022-10-08 at 10 38 04 PM

Example of multiple form groups:

Screen Shot 2022-09-27 at 10 44 03 PM

Validation

This Form component is designed to work with Astro Reactive Validator, our package for setting up validators easily.

We are opensource!

👉 All contributions are welcome. Let's make the fastest web forms powered by Astro.

👉 This package is a work in progress. See the change log.