astro-reactive-form/packages/astro-reactive-form
2022-10-04 16:12:19 +02:00
..
components refactor(Field.astro): handling of labelPosition 2022-10-01 20:33:47 +02:00
core Fix #6: refactored IFormControl to FormControlBase and added radio prop. 2022-10-02 20:41:47 +05:30
test chore: update project command scripts 2022-10-04 14:30:00 +02:00
.editorconfig chore: clean up monorepo 2022-10-01 15:44:39 +02:00
.eslintignore chore: clean up monorepo 2022-10-01 15:44:39 +02:00
.eslintrc.cjs chore: clean up monorepo 2022-10-01 15:44:39 +02:00
.prettierrc.cjs chore: clean up monorepo 2022-10-01 15:44:39 +02:00
Form.astro fix: main branch tests 2022-10-04 16:12:19 +02:00
index.ts fix: removed default export 2022-10-03 07:56:52 +02:00
package.json fix: main branch tests 2022-10-04 16:12:19 +02:00
README.md chore: update library and package readme; update license; add assets 2022-10-04 13:51:30 +02:00
RELEASE.md docs: update astro-reactive-form RELEASE 2022-10-04 14:04:35 +02:00
tsconfig.json move astro-reactive-form to separate workspace 2022-10-01 14:18:16 +02:00

package-form-cover

npm npm npm github

Astro Reactive Form 🔥

Generate a dynamic form which can be modified programatically. The Reactive Form component for Astro 🔥

All contributions are welcome.

Installation

In your Astro project:

npm i astro-reactive-form

Usage

Use in an Astro page:

---
import { FormControl, FormGroup } from "astro-reactive-form/core";
import Form from "astro-reactive-form";

// create a form group (rendered as <fieldset>)
const form = new FormGroup([
  {
    name: "username",
    label: "Username",
  },
  {
    name: "password",
    label: "Password",
    type: "password",
  },
]);

// set the name (rendered as <legend>)
form.name = "Simple Form";

// insert a control
form.controls.push(
  new FormControl({
    type: "checkbox",
    name: "is-awesome",
    label: "is Awesome?",
    labelPosition: "right",
  })
);

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

// set values dynamically
userNameControl?.setValue("RAMOOOON");
form.get('is-awesome')?.setValue("checked");
---

<!-- the formGroups attribute takes an array of FormGroup-->
<Form formGroups={[form]} />

Screenshots

Result of example above:

Screen Shot 2022-10-01 at 7 29 00 PM

Example of multiple form groups:

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

Future Plans

Currently this only supports very basic form creation, but the goal of the project is ambitious:

  1. Validator library for common validation scenarios
    1. Client-side validation
    2. Server-side validation
    3. validation hooks - onFocus, onBlur, onSubmit
  2. Themes - unstyled, light mode, dark mode, compact, large
  3. FormGroup class
    1. statusChanges - observable that emits the form status when it changes
    2. valueChanges - observable that emits the values of all controls when they change
  4. FormControl class
    1. statusChanges - observable that emits the control status when it changes
    2. valueChanges - observable that emits the control value when it changes
    3. value - property that reflects the control value
  5. Documentation website

... and so much more

All contributions are welcome. Let's make the fastest web form component powered by Astro