{"id":17528618,"url":"https://github.com/jucian0/solidjs-createform","last_synced_at":"2025-04-23T18:23:12.732Z","repository":{"id":37295233,"uuid":"498936311","full_name":"jucian0/solidjs-createform","owner":"jucian0","description":"Delightful SolidJs forms","archived":false,"fork":false,"pushed_at":"2022-07-16T21:17:31.000Z","size":595,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T11:40:05.892Z","etag":null,"topics":["form","form-builder","form-validation","hacktoberfest","hacktoberfest2023","javascript","solidjs","tyoescript","typescript-library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jucian0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2022-06-02T00:12:31.000Z","updated_at":"2023-10-10T00:42:53.000Z","dependencies_parsed_at":"2022-07-12T05:30:20.823Z","dependency_job_id":null,"html_url":"https://github.com/jucian0/solidjs-createform","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jucian0%2Fsolidjs-createform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jucian0%2Fsolidjs-createform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jucian0%2Fsolidjs-createform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jucian0%2Fsolidjs-createform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jucian0","download_url":"https://codeload.github.com/jucian0/solidjs-createform/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250488184,"owners_count":21438732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["form","form-builder","form-validation","hacktoberfest","hacktoberfest2023","javascript","solidjs","tyoescript","typescript-library"],"created_at":"2024-10-20T15:44:22.342Z","updated_at":"2025-04-23T18:23:12.714Z","avatar_url":"https://github.com/jucian0.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome to Solidjs createform 👋\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Jucian0/solidjs-createform/blob/main/LICENCE)\n[![](https://img.shields.io/badge/version-1.0.1-orange.svg)](https://github.com/Jucian0/solidjs-createform/releases/tag/v1.0.1)\n[![COverage](https://img.shields.io/badge/coverage-98.31%25-green)](coverage)\n[![COverage](https://img.shields.io/badge/npm-v1.0.1-red)](https://www.npmjs.com/package/solid-js-createform)\n\n\u003e A SolidJS package to create forms easily and quickly.\n\n# createform\n\nCreateform is an open-source package to create forms for SolidJS applications. It's based on [useForm](https://github.com/Jucian0/useform)\n\n## Motivation\n\nI decided to create a package that could simplify the creation of forms, and, make it easier to use. After a quick research, I found that there are not many packages to create forms for SolidJs, so I decided to create one, that could be used by anyone.\n\nThe main idea is to create a form easily and quickly, without many lines of code, fortunately, SolidJs provides us a powerful and easy way to do that.\n\n- Creates form with fields\n- Creates form with validation\n- Supports custom fields\n- Update touched state of form fields independently or all together\n- Update values state of form fields independently or all together\n- Update errors state of form fields independently or all together\n\n## How to use it\n\nTo use `createform` you need to import it into your SolidJS application.\n\n```js\nimport { createForm } from 'solid-js-createform'\n```\n\nThen you can create a form.\n\n```js\nconst form = createForm({\n  initialValues: {\n    name: '',\n    email: '',\n    password: ''\n  }\n})\n```\n\nNow you can use it everywhere in your SolidJS application.\n\n```js\nfunction App() {\n  const { register, handleSubmit, errors } = form\n\n  function onSubmit(data) {\n    console.log(data)\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cform onSubmit={handleSubmit(onSubmit)}\u003e\n        \u003cinput {...register('name', 'text')} /\u003e\n        \u003cinput {...register('email', 'email')} /\u003e\n        \u003cinput {...register('password', 'password')} /\u003e\n        \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\n      \u003c/form\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n## Validation\n\nCreateForm uses yup validation schema, so you just need to pass a validation schema to the `createForm` function.\n\n```js\nconst form = createForm({\n  initialValues: {\n    name: '',\n    email: '',\n    password: ''\n  },\n  validationSchema: yup.object({\n    name: yup.string().required('Name is required'),\n    email: yup.string().email('Invalid email').required('Email is required'),\n    password: yup\n      .string()\n      .min(6, 'Password must be at least 6 characters')\n      .required('Password is required')\n  })\n})\n```\n\n## API\n\n`createForm` receives an object with the following properties:\n\n### `initialValues`: An object with the initial values of the form.\n\n### `validationSchema`: A validation schema to validate the form. By default, `createForm` uses yup validation schema.\n\n`createForm` returns an object with the following properties:\n\n### `register`: Register a field to the form.\n\n```js\nconst form = createForm({\n  initialValues: {\n    name: '',\n    email: '',\n    password: ''\n  }\n})\n\nconst { register, handleSubmit, errors } = form\n\n\u003cinput {...register('name', 'text')} /\u003e\n```\n\n### `handleSubmit`: Handle form submit.\n\n```jsx\nconst form = createForm...\n\nconst { register, handleSubmit, errors } = form\n\n\u003cform onSubmit={handleSubmit(onSubmit)}\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cinput {...register('email', 'email')} /\u003e\n  \u003cinput {...register('password', 'password')} /\u003e\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### `errors`: Get errors of the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors } = form\n\n\u003cform onSubmit={handleSubmit(onSubmit)}\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cspan\u003e {errors.name}\u003c/span\u003e\n\u003c/form\u003e\n```\n\n### `touched`: Get touched state of the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, touched } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cspan\u003e {touched.name ? errors.name : ''}\u003c/span\u003e\n\u003c/form\u003e\n```\n\n### `values`: Get values of the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, values } = form\n\ncreateEffect(() =\u003e {\n  console.log(values.name)\n})\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n\u003c/form\u003e\n```\n\n### `setTouched`: Set the touched state of the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, setTouched } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cbutton onClick={() =\u003e setTouched('name')}\u003eTouch\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### `setValues`: Set the values of the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, setValues } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cbutton onClick={() =\u003e setValues({ name: 'John' })}\u003eSet values\u003c/button\u003e\n\u003c/form\u003e\n```\n\nor\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, setValues } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cbutton onClick={() =\u003e setValues('name','John')}\u003eSet values\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### `setErrors`: Set errors of the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, setErrors } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cbutton onClick={() =\u003e setErrors('name', 'Name is required')}\u003eSet errors\u003c/button\u003e\n\u003c/form\u003e\n```\n\nor\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, setErrors } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cbutton onClick={() =\u003e setErrors({name:'Name is required'})}\u003eSet errors\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### `resetForm`: Reset the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, resetForm } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cbutton onClick={() =\u003e resetForm()}\u003eReset form\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### `resetValues`: Reset values of the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, resetValues } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cbutton onClick={() =\u003e resetValues()}\u003eReset values\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### `resetErrors`: Reset errors of the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, resetErrors } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cbutton onClick={() =\u003e resetErrors()}\u003eReset errors\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### `resetTouched`: Reset the touched state of the form.\n\n```jsx\nconst form = createForm...\nconst { register, handleSubmit, errors, resetTouched } = form\n\n\u003cform\u003e\n  \u003cinput {...register('name', 'text')} /\u003e\n  \u003cbutton onClick={() =\u003e resetTouched()}\u003eReset touched\u003c/button\u003e\n\u003c/form\u003e\n```\n\n## Let us know what you think\n\nFeel free to [open an issue](https://github.com/Jucian0/solidjs-createform/issues) if you have any feedback, or if you want to contribute.\n\n## Show your support\n\nGive us a star on [GitHub](https://github.com/Jucian0/solidjs-createform) if you like this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjucian0%2Fsolidjs-createform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjucian0%2Fsolidjs-createform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjucian0%2Fsolidjs-createform/lists"}