Gathering detailed insights and metrics for formlid-js
Gathering detailed insights and metrics for formlid-js
Gathering detailed insights and metrics for formlid-js
Gathering detailed insights and metrics for formlid-js
npm install formlid-js
Typescript
Module System
Node Version
NPM Version
70.2
Supply Chain
98.9
Quality
75.4
Maintenance
100
Vulnerability
100
License
TypeScript (99.25%)
JavaScript (0.75%)
Total Downloads
1,127
Last Day
1
Last Week
1
Last Month
2
Last Year
183
37 Commits
1 Forks
1 Watching
1 Branches
2 Contributors
Latest Version
2.0.0
Package Id
formlid-js@2.0.0
Unpacked Size
58.32 kB
Size
12.38 kB
File Count
58
NPM Version
9.8.1
Node Version
20.0.0
Publised On
03 Sept 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
1
Compared to previous week
Last month
-75%
2
Compared to previous month
Last year
-80.6%
183
Compared to previous year
Formlid-js is Form helper package for Solid-JS with Yup as the validation schema
1npm i formlid-js
If you encounter ReferenceError: React is not defined.
Add the code below in the vite.config.ts
1export default defineConfig({ 2 ... 3 optimizeDeps: { 4 include: [], 5 exclude: ['formlid-js'], 6 } 7});
try to check projects under examples/
create formlid store.
1 // formlid value type 2 interface InitialValue { 3 email: string; 4 password: string; 5 age?: number; 6 checked: boolean[]; 7 } 8 9 ... 10 11 const { field, meta, form } = createFormlid<InitialValue>({ 12 initialValues: { 13 email: '', 14 password: '', 15 checked: [], 16 }, 17 validationSchema: { 18 email: yup.string().required().email('enter a valid email'), 19 password: yup.string().required().min(8, 'be at least 8 characters long'), 20 checked: yup.array().of(yup.boolean().required()).required(), 21 }, 22 onsubmit: async (data, helpers) => { 23 await delya(1500); // wait for 1500ms 24 alert(`submitted!\nemail: ${data.email}\npassword: ${data.password}`); 25 console.log(helpers.getValues()); 26 }, 27 }); 28 29 ... 30 31 32 return ( 33 <form {...form()}> 34 <div> 35 <label>e-mail</label> 36 <input {...field('email')} autocomplete="off" /> 37 </div> 38 <div> 39 <label>password</label> 40 <input type="password" {...field('password')} autocomplete="off" /> 41 </div> 42 <button type="submit" disabled={form.isSubmitting()}> 43 submit after 1500ms 44 </button> 45 </form> 46 );
1// App.tsx 2 3 // formlid value type 4 interface InitialValue { 5 email: string; 6 password: string; 7 age?: number; 8 checked: boolean[]; 9 } 10 11 ... 12 13 const { form, FormlidProvider } = Formlid({ 14 initialValues: { 15 email: '', 16 password: '', 17 checked: [], 18 }, 19 validationSchema: { 20 email: yup.string().required().email('enter a valid email'), 21 password: yup.string().required().min(8, 'be at least 8 characters long'), 22 checked: yup.array().of(yup.boolean().required()).required(), 23 }, 24 onsubmit: async (data, helpers) => { 25 await delya(1500); // wait for 1500ms 26 alert(`submitted!\nemail: ${data.email}\npassword: ${data.password}`); 27 console.log(helpers.getValues()); 28 }, 29 }); 30 31 ... 32 33 return ( 34 <form {...form()}> 35 <FormlidProvider> 36 <!-- custom components --> 37 <Field name="email" /> 38 <Field name="password" /> 39 <button type="submit" disabled={form.isSubmitting()}> 40 submit 41 </button> 42 </FormlidProvider> 43 </form> 44 ); 45 46// Field.tsx 47 48const Field = (props) => { 49 const {field, meta, helpers} = useField(props.name); 50 51 ... 52 53 return ( 54 <div> 55 <label>{props.name}</label> 56 <input {...field()} value={`${field().value}`} /> 57 </div> 58 ); 59} 60
arguments | Required | type | description |
---|---|---|---|
initialValues | Required | TFormValue; | initial value of form |
validationSchema | Optional | {[key in string]: Yup.Schema} | yup validation schema |
onsubmit | Required | (formData: TFormValue, helpers: FormlidSubmitHelpers<TFormValue>) => any | Promise<any>; | callback function when submit the form |
validateOnSubmitOnly | Optional | boolean | Accessor<boolean>; | validate with validation schema when submit is emitted only |
field | type |
---|---|
form | FormlidFormHelpers |
field | FormlidFieldHelpers |
meta | FormlidMetaHelpers |
helpers | FormlidHelpers |
FormlidProvider | FormlidProviderComponent |
It is a wrapper function of useContext. when you should call createFormlid() in a parent component of the component that has form element.
Thus, you should use call useForm() in a child component under the FormlidProvider.
It returns same object as createFormlid() without FormlidProvider.
1 2 const { field } = useForm(); 3 4 return ( 5 <div> 6 <label>{props.name}</label> 7 <input {...field()} /> 8 </div> 9 ); 10
arguments | Required | type | description |
---|
field | type |
---|---|
form | FormlidFormHelpers |
field | FormlidFieldHelpers |
meta | FormlidMetaHelpers |
helpers | FormlidHelpers |
It is a wrapper function of useContext. when you should call createFormlid() in a parent component of the component that has form element.
Thus, you should use call useForm() in a child component under the FormlidProvider.
It returns same object as createFormlid() without FormlidProvider.
You do not need to forward the name When calling a function that previously required a name like field(), meta(), helpers.setValue(), etc.
1 2 const { field } = useField('name'); 3 4 return ( 5 <div> 6 <label>{props.name}</label> 7 <input {...field()} /> 8 </div> 9 ); 10
arguments | type | description |
---|---|---|
name | keyof TFormValue | One of the key of the initialValue. |
field | type |
---|---|
form | UseFieldFormHelpers |
field | UseFieldFieldHelpers |
meta | UseFieldMetaHelpers |
helpers | UseFieldHelpers |
It is type of value which a formlid store and manage. initialValues props of createFormlid() follows this type
1 TFormValue: object
[ ] Write Types, Field in README.md
[ ] Write tests
[ ] Add reactive on initialValues & validationSchema to createFormlid props
[ ] refactor Signals to Store
"Pull Requests are welcome."
For major changes, please open an issue first to discuss what you would like to change.
No vulnerabilities found.
No security vulnerabilities found.