astro-reactive-form/packages/form
Ayo Ayco 4dc020027f
feat: create astro reactive validator (#90)
* feat: initial validator component

* chore: fix eslint for validator

* chore: update package info for validator

* chore: remove vscode settings for docs

* chore: put docs and demo into apps

* chore: move package scope @astro-reactive

* test: update tests for validator

* feat: validator functions, hooks

* feat: validator sets haserrors attribute

* feat: use data-validator attributes

* feat: showValidationHints

* feature: add logic for all validators

* refactor: remove Validator component usage

* docs(validator): initial readme

* chore: comment out unsupported validator

* docs(validator): update installation

* chore: package docs and publish

* chore: update deps

* docs: update npm info on docs

* docs(validator): update docs for validator

* fix(form): handle undefined form

* test(validator): update tests

* chore: organize files; update deps

* chore: fix build scripts
2022-10-15 16:32:02 +02:00
..
components feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
core feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
test feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +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 feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
.prettierrc.cjs feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
Form.astro feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
index.ts feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
package.json feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
README.md feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +02:00
RELEASE.md feat: create astro reactive validator (#90) 2022-10-15 16:32:02 +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 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

Validation

See our package for setting up validators.

Future Plans

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

  1. Themes - unstyled, light mode, dark mode, compact, large
  2. 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
  3. FormControl class
    1. statusChanges - observable that emits the control status when it changes
    2. valueChanges - observable that emits the control value when it changes
  4. Documentation website

... and so much more

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