astro-reactive-form/packages/form
Woramat Ngamkham 975b2e821a
feat(form): add validateOnLoad prop (#213)
* feat(form): add validateOnLoad prop

* feat(form): add FormConfig interface

* refactor(form): refactor FormConfig

* refactor(demo): change params to FormConfig

* chore(demo): remove FormConfig on demo

* feat(form): make validateOnLoad to be false by default

* feat(form): add setValidateOnLoad method

* chore(form): edit comment on validateOnLoad

* feat(form): remove setValidateOnLoad in FormGroup

* revert(form): add FormConfig interface

This reverts commit 44b58d4a43d4d2e8bcd3dc799e3110f9b8f23604.

* revert(demo): change params to FormConfig

This reverts commit 98f8602000505a29d04493617043aa0cfb00a969.
2022-11-30 15:28:48 +07:00
..
components feat(form): add validateOnLoad prop (#213) 2022-11-30 15:28:48 +07:00
core feat(form): add validateOnLoad prop (#213) 2022-11-30 15:28:48 +07:00
test test(form): Added test Field.astro to test for category validation prop (#217) 2022-11-29 20:34:11 +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 core: common directory for packages (#114) 2022-10-21 14:05:23 +02:00
.prettierrc.cjs feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
index.ts refactor: form package cleanup (#135) 2022-10-23 23:04:40 +02:00
package.json chore(library): implement turporepo (#206) 2022-11-23 20:05:07 +01:00
README.md refactor(form): deprecate labelPosition (#172) 2022-11-01 16:24:29 +01:00
RELEASE.md chore: release common, form, validator 2022-11-05 09:23:42 +01:00
tsconfig.json chore: update check and build scripts 2022-11-10 19:03:45 +01:00
vitest.config.ts fix: extends timeout for timed out test (#208) 2022-11-25 14:37:23 +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",
  },
]);

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

// 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.