astro-reactive-form/packages/astro-reactive-form
2022-10-13 13:55:38 +02:00
..
client feat: initial form control state (#60) 2022-10-07 07:35:01 +02:00
components [feat]:Form control state #4 (#58) 2022-10-06 23:19:49 +02:00
core feat: initial form control state (#60) 2022-10-07 07:35:01 +02:00
test feat: support single form group (#71) 2022-10-08 22:29:08 +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 devops: set up package linting (#53) 2022-10-06 16:01:23 +02:00
Form.astro feat: support single form group (#71) 2022-10-08 22:29:08 +02:00
index.ts feat: initial form control state (#60) 2022-10-07 07:35:01 +02:00
package.json docs:update email (#85) 2022-10-13 13:55:38 +02:00
README.md docs: update readmes (#83) 2022-10-13 10:10:31 +02:00
RELEASE.md chore: update release docs (#84) 2022-10-13 10:17:11 +02:00
tsconfig.json devops: set up package tsc build check (#56) 2022-10-06 16:46:44 +02:00

Astro Reactive Library Logo 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 { FormControl, FormGroup } from "astro-reactive-form/core";
import Form 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:

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

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
  5. Documentation website

... and so much more

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