solid-hook-form 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # Solid Hook Form
2
2
 
3
- ### Playground
3
+ [<img width="1171" alt="Screenshot 2025-04-05 at 15 01 47" src="https://github.com/tatsmaki/solid-hook-form/blob/master/assets/demo.png" />](https://tatsmaki.github.io/solid-hook-form)
4
4
 
5
- [<img width="1171" alt="Screenshot 2025-04-05 at 15 01 47" src="https://github.com/tatsmaki/solid-hook-form/blob/master/assets/demo.png" />](https://solid-hook-form.vercel.app/)
5
+ <p align="center">
6
+ <a href="https://tatsmaki.github.io/solid-hook-form/#/quickstart">Get started</a> |
7
+ <a href="https://solid-hook-form.vercel.app/">Playground</a>
8
+ </p>
9
+
10
+ ### Features
11
+
12
+ - Embraces native HTML form [validation](https://tatsmaki.github.io/solid-hook-form/#/quickstart?id=apply-validation)
13
+ - [Small size](https://bundlephobia.com/package/solid-hook-form@latest) and no [dependencies](./package.json)
14
+ - TypeScript [support](https://tatsmaki.github.io/solid-hook-form/#/quickstart?id=typescript)
6
15
 
7
16
  ### Install
8
17
 
@@ -10,42 +19,23 @@
10
19
  npm install solid-hook-form
11
20
  ```
12
21
 
13
- ### Quickstart
22
+ ### Quick start
14
23
 
15
- ```tsx
24
+ ```jsx
16
25
  import { useForm } from "solid-hook-form";
17
26
 
18
- const Form = () => {
19
- const { errors, isValid, register, onSubmit } = useForm({
27
+ const ExampleForm = () => {
28
+ const { errors, register, onSubmit } = useForm({
20
29
  defaultValues: {
21
- date: new Date().toISOString().split("T")[0],
22
- email: "",
23
- password: "",
24
- age: 0,
25
- remember: false,
30
+ name: "",
26
31
  },
27
32
  });
28
33
 
34
+ const submitExample = (values) => console.log(values);
35
+
29
36
  return (
30
- <form onSubmit={onSubmit(handleSubmit)}>
31
- <input type="date" {...register("date", { required: "Required" })} />;
32
- <input
33
- {...register("email", {
34
- required: "Required",
35
- pattern: {
36
- value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
37
- message: "Invalid email",
38
- },
39
- })}
40
- />
41
- <input
42
- {...register("password", {
43
- required: "Required",
44
- minLength: { value: 8, message: "Min 8" },
45
- })}
46
- />
47
- <input type="number" {...register("age", { min: 18, max: 100 })} />
48
- <input type="checkbox" {...register("remember", { required: "Required" })} />
37
+ <form onSubmit={onSubmit(submitExample)}>
38
+ <input {...register("name", { minLength: 2, pattern: /[A-Za-z]/ })} />;
49
39
  <button type="submit">Submit</button>
50
40
  </form>
51
41
  );
@@ -6,4 +6,5 @@ export declare const createErrors: <F extends FormValues>() => {
6
6
  appendError: (name: Path<F>, error: FieldError) => void;
7
7
  removeError: (name: Path<F>) => void;
8
8
  resetErrors: () => void;
9
+ getError: (name: string) => any;
9
10
  };
@@ -0,0 +1,6 @@
1
+ import { FormFields, Ref } from '../types/form';
2
+ export declare const createFields: () => {
3
+ fields: FormFields;
4
+ getField: (name: string) => Ref;
5
+ setField: (name: string, element: Ref) => void;
6
+ };
@@ -0,0 +1,8 @@
1
+ import { FormValues } from '../types/form';
2
+ import { Path } from '../types/path';
3
+ import { Rules } from '../types/validate';
4
+ export declare const createRules: <F extends FormValues>() => {
5
+ rules: Record<string, Rules<F, Path<F>>>;
6
+ addRule: (name: string, options: Rules<F, Path<F>>) => void;
7
+ getRule: (name: string) => Rules<F, Path<F>>;
8
+ };