astro-reactive-form/packages/form
2022-10-20 16:14:33 +02:00
..
components feat(form): Add radio (#111) 2022-10-20 07:58:40 +02:00
core feat(form): Add radio (#111) 2022-10-20 07:58:40 +02:00
test test(packages/form): Added some tests for Field and FieldSet components (#119) 2022-10-20 16:14:33 +02: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 chore: Shared eslint + prettier for packages (#117) 2022-10-20 11:59:04 +02:00
.prettierrc.cjs feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
Form.astro feat(form): Add radio (#111) 2022-10-20 07:58:40 +02:00
index.ts feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
package.json chore: patch packages (#108) 2022-10-18 12:16:58 +02:00
README.md docs(form): remove typo on readme 2022-10-16 13:36:35 +02:00
RELEASE.md chore(packages): bump patch 2022-10-16 10:33:35 +02:00
tsconfig.json feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02: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",
  },
]);

// 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");
---

<Form
  formGroups={form}
  submitControl={{
    type: "submit",
    name: "submit",
  }}
/>
<!-- 
  The `formGroups` attribute can take a single FormGroup
  or an array of FormGroup for multiple fieldset blocks;
  we are using a single FormGroup for now in this example.
-->

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 under rigorous development. See the change log.