solid-hook-form 1.4.0 → 1.4.2
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 +20 -30
- package/dist/logic/get_value.d.ts +1 -1
- package/dist/main.js +1 -1
- package/dist/main.umd.cjs +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
# Solid Hook Form
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
22
|
+
### Quick start
|
|
14
23
|
|
|
15
|
-
```
|
|
24
|
+
```jsx
|
|
16
25
|
import { useForm } from "solid-hook-form";
|
|
17
26
|
|
|
18
|
-
const
|
|
19
|
-
const { errors,
|
|
27
|
+
const ExampleForm = () => {
|
|
28
|
+
const { errors, register, onSubmit } = useForm({
|
|
20
29
|
defaultValues: {
|
|
21
|
-
|
|
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(
|
|
31
|
-
<input
|
|
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
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getFieldValue: (event: Event) => string | boolean |
|
|
1
|
+
export declare const getFieldValue: (event: Event) => string | boolean | File[];
|
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createSignal as d, createContext as H, createComponent as T, useContext as q } from "solid-js";
|
|
2
2
|
const S = (e) => {
|
|
3
3
|
const n = e.target;
|
|
4
|
-
return n instanceof HTMLSelectElement ? n.value : n instanceof HTMLInputElement && n.type === "checkbox" ? n.checked : n instanceof HTMLInputElement && n.type === "file" ? n.files : n.value;
|
|
4
|
+
return n instanceof HTMLSelectElement ? n.value : n instanceof HTMLInputElement && n.type === "checkbox" ? n.checked : n instanceof HTMLInputElement && n.type === "file" ? [...n.files || []] : n.value;
|
|
5
5
|
}, y = (e, n) => {
|
|
6
6
|
if (e instanceof HTMLSelectElement) {
|
|
7
7
|
e.value = n;
|
package/dist/main.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("solid-js")):typeof define=="function"&&define.amd?define(["exports","solid-js"],a):(f=typeof globalThis<"u"?globalThis:f||self,a(f["solid-hook-form"]={},f.solid))})(this,function(f,a){"use strict";const b=e=>{const n=e.target;return n instanceof HTMLSelectElement?n.value:n instanceof HTMLInputElement&&n.type==="checkbox"?n.checked:n instanceof HTMLInputElement&&n.type==="file"?n.files:n.value},h=(e,n)=>{if(e instanceof HTMLSelectElement){e.value=n;return}if(e instanceof HTMLInputElement&&e.type==="checkbox"){e.checked=n;return}e instanceof HTMLInputElement&&e.type==="file"||(e.value=n)},l=e=>e instanceof RegExp||typeof e=="string"||typeof e=="number"?e:e.value,d=e=>typeof e=="string"?e:typeof e.message=="string"?e.message:"",C=(e,n,r={})=>{const s=e[n];if(r.required&&!s)return{type:"required",message:d(r.required)};if(r.min&&Number(s)<Number(l(r.min)))return{type:"min",message:d(r.min)};if(r.max&&Number(s)>Number(l(r.max)))return{type:"max",message:d(r.max)};if(r.minLength&&s.length<l(r.minLength))return{type:"minLength",message:d(r.minLength)};if(r.maxLength&&s.length>l(r.maxLength))return{type:"maxLength",message:d(r.maxLength)};if(r.pattern&&!l(r.pattern).test(s))return{type:"pattern",message:d(r.pattern)};if(r.validate){const c=r.validate(s,e);if(c===!1)return{type:"validate"};if(typeof c=="string")return{type:"validate",message:c}}},k=()=>{const[e,n]=a.createSignal({});return{errors:e,appendError:(u,m)=>{n(p=>({...p,[u]:m}))},removeError:u=>{n(m=>{const p={...m};return delete p[u],p})},resetErrors:()=>{n({})}}},I=({defaultValues:e,mode:n="onInput"})=>{const r={},s={},[c,u]=a.createSignal(e),{errors:m,appendError:p,removeError:M,resetErrors:V}=k(),[v,E]=a.createSignal(!0),j=(t,o)=>{const i=r[t];i&&(o.ref=i),p(t,o)},q=t=>{M(t)},x=t=>{const o=s[t],i=C(c(),t,o);i?j(t,i):q(t),E(!Object.keys(m()).length)},H=()=>{Object.keys(c()).forEach(t=>{x(t)})},P=()=>{var o;const t=Object.keys(r);for(const i of t){const g=m()[i];if(g){(o=g.ref)==null||o.focus();break}}},L=(t,o)=>{const i=b(t);u(g=>({...g,[o]:i})),x(o)},N=(t,o={})=>(s[t]={required:o.required,min:o.min,max:o.max,minLength:o.minLength,maxLength:o.maxLength,pattern:o.pattern,validate:o.validate},{name:t,onInput(i){n==="onInput"&&L(i,t)},onChange(i){(n==="onChange"||n==="onInput")&&L(i,t)},ref(i){r[t]||(r[t]=i,i&&h(i,c()[t]))}}),F=t=>t?c()[t]:c();return{values:c,errors:m,isValid:v,register:N,getValues:F,setValue:(t,o)=>{u(g=>({...g,[t]:o}));const i=r[t];i&&h(i,o)},onSubmit:t=>o=>{o.preventDefault(),H(),v()&&t(F()),P()},reset:(t={})=>{u(()=>({...e,...t})),V(),E(!0)}}},y=a.createContext(),S=e=>a.createComponent(y.Provider,{get value(){return e.form},get children(){return e.children}}),T=()=>{const e=a.useContext(y);if(!e)throw new Error("useFormContext: cannot find a FormProvider");return e};f.FormProvider=S,f.useForm=I,f.useFormContext=T,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(f,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("solid-js")):typeof define=="function"&&define.amd?define(["exports","solid-js"],a):(f=typeof globalThis<"u"?globalThis:f||self,a(f["solid-hook-form"]={},f.solid))})(this,function(f,a){"use strict";const b=e=>{const n=e.target;return n instanceof HTMLSelectElement?n.value:n instanceof HTMLInputElement&&n.type==="checkbox"?n.checked:n instanceof HTMLInputElement&&n.type==="file"?[...n.files||[]]:n.value},h=(e,n)=>{if(e instanceof HTMLSelectElement){e.value=n;return}if(e instanceof HTMLInputElement&&e.type==="checkbox"){e.checked=n;return}e instanceof HTMLInputElement&&e.type==="file"||(e.value=n)},l=e=>e instanceof RegExp||typeof e=="string"||typeof e=="number"?e:e.value,d=e=>typeof e=="string"?e:typeof e.message=="string"?e.message:"",C=(e,n,r={})=>{const s=e[n];if(r.required&&!s)return{type:"required",message:d(r.required)};if(r.min&&Number(s)<Number(l(r.min)))return{type:"min",message:d(r.min)};if(r.max&&Number(s)>Number(l(r.max)))return{type:"max",message:d(r.max)};if(r.minLength&&s.length<l(r.minLength))return{type:"minLength",message:d(r.minLength)};if(r.maxLength&&s.length>l(r.maxLength))return{type:"maxLength",message:d(r.maxLength)};if(r.pattern&&!l(r.pattern).test(s))return{type:"pattern",message:d(r.pattern)};if(r.validate){const c=r.validate(s,e);if(c===!1)return{type:"validate"};if(typeof c=="string")return{type:"validate",message:c}}},k=()=>{const[e,n]=a.createSignal({});return{errors:e,appendError:(u,m)=>{n(p=>({...p,[u]:m}))},removeError:u=>{n(m=>{const p={...m};return delete p[u],p})},resetErrors:()=>{n({})}}},I=({defaultValues:e,mode:n="onInput"})=>{const r={},s={},[c,u]=a.createSignal(e),{errors:m,appendError:p,removeError:M,resetErrors:V}=k(),[v,E]=a.createSignal(!0),j=(t,o)=>{const i=r[t];i&&(o.ref=i),p(t,o)},q=t=>{M(t)},x=t=>{const o=s[t],i=C(c(),t,o);i?j(t,i):q(t),E(!Object.keys(m()).length)},H=()=>{Object.keys(c()).forEach(t=>{x(t)})},P=()=>{var o;const t=Object.keys(r);for(const i of t){const g=m()[i];if(g){(o=g.ref)==null||o.focus();break}}},L=(t,o)=>{const i=b(t);u(g=>({...g,[o]:i})),x(o)},N=(t,o={})=>(s[t]={required:o.required,min:o.min,max:o.max,minLength:o.minLength,maxLength:o.maxLength,pattern:o.pattern,validate:o.validate},{name:t,onInput(i){n==="onInput"&&L(i,t)},onChange(i){(n==="onChange"||n==="onInput")&&L(i,t)},ref(i){r[t]||(r[t]=i,i&&h(i,c()[t]))}}),F=t=>t?c()[t]:c();return{values:c,errors:m,isValid:v,register:N,getValues:F,setValue:(t,o)=>{u(g=>({...g,[t]:o}));const i=r[t];i&&h(i,o)},onSubmit:t=>o=>{o.preventDefault(),H(),v()&&t(F()),P()},reset:(t={})=>{u(()=>({...e,...t})),V(),E(!0)}}},y=a.createContext(),S=e=>a.createComponent(y.Provider,{get value(){return e.form},get children(){return e.children}}),T=()=>{const e=a.useContext(y);if(!e)throw new Error("useFormContext: cannot find a FormProvider");return e};f.FormProvider=S,f.useForm=I,f.useFormContext=T,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-hook-form",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/main.umd.cjs",
|
|
6
6
|
"module": "./dist/main.js",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@solidjs/testing-library": "^0.8.10",
|
|
23
23
|
"@testing-library/user-event": "^14.6.1",
|
|
24
|
+
"docsify-cli": "^4.4.4",
|
|
24
25
|
"happy-dom": "^17.4.4",
|
|
25
26
|
"react-hook-form": "^7.55.0",
|
|
26
27
|
"typescript": "~5.7.2",
|
|
@@ -33,7 +34,8 @@
|
|
|
33
34
|
"start": "vite --config vite.demo",
|
|
34
35
|
"build": "tsc && vite build",
|
|
35
36
|
"build:demo": "tsc && vite build --config vite.demo",
|
|
36
|
-
"test": "vitest run"
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"start:docs": "npx docsify serve src-docs"
|
|
37
39
|
},
|
|
38
40
|
"author": "thorn_pear",
|
|
39
41
|
"license": "ISC",
|
|
@@ -42,6 +44,7 @@
|
|
|
42
44
|
"type": "git",
|
|
43
45
|
"url": "https://github.com/tatsmaki/solid-hook-form.git"
|
|
44
46
|
},
|
|
47
|
+
"homepage": "https://tatsmaki.github.io/solid-hook-form",
|
|
45
48
|
"keywords": [
|
|
46
49
|
"solid",
|
|
47
50
|
"hooks",
|