{"id":20090859,"url":"https://github.com/santigarcor/laravel-form-js","last_synced_at":"2025-09-02T20:51:29.273Z","repository":{"id":66340333,"uuid":"106354318","full_name":"santigarcor/laravel-form-js","owner":"santigarcor","description":null,"archived":false,"fork":false,"pushed_at":"2018-07-19T02:33:12.000Z","size":37,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T05:27:52.452Z","etag":null,"topics":["form","javascript","laravel","validation-errors"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/santigarcor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-10T01:37:15.000Z","updated_at":"2023-09-25T20:27:41.000Z","dependencies_parsed_at":"2023-02-25T08:31:13.337Z","dependency_job_id":null,"html_url":"https://github.com/santigarcor/laravel-form-js","commit_stats":null,"previous_names":["santigarcor/form-js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigarcor%2Flaravel-form-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigarcor%2Flaravel-form-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigarcor%2Flaravel-form-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigarcor%2Flaravel-form-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/santigarcor","download_url":"https://codeload.github.com/santigarcor/laravel-form-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241404375,"owners_count":19957652,"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","javascript","laravel","validation-errors"],"created_at":"2024-11-13T16:26:45.191Z","updated_at":"2025-03-02T15:26:42.031Z","avatar_url":"https://github.com/santigarcor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Form Javascript Object\n\n[![Build Status](https://travis-ci.org/santigarcor/laravel-form-js.svg?branch=master)](https://travis-ci.org/santigarcor/laravel-form-js)\n[![npm](https://img.shields.io/npm/v/laravel-form-js.svg)](https://www.npmjs.com/package/laravel-form-js)\n[![npm](https://img.shields.io/npm/dt/laravel-form-js.svg)](https://www.npmjs.com/package/laravel-form-js)\n[![license](https://img.shields.io/github/license/santigarcor/laravel-form-js.svg)](https://www.npmjs.com/package/laravel-form-js)\n\nThis is a package for handling forms using an object oriented approach.\n\n## Installation\nIn your console run:\n```bash\n  # Using npm\n  npm install laravel-form-js\n\n  # Using yarn\n  yarn add laravel-form-js\n```\n\n## Usage\nExample using Vue\n```javascript\n\u003ctemplate\u003e\n  \u003cform @submit.prevent=\"submit\"\u003e\n    \u003cinput type=\"text\" name=\"name\" v-model=\"form.name\"\u003e\n    \u003cdiv v-text=\"form.errorsFor('name')\"\u003e\u003c/div\u003e\n\n    \u003cinput type=\"text\" name=\"email\" v-model=\"form.email\"\u003e\n    \u003cdiv v-text=\"form.errorsFor('email')\"\u003e\u003c/div\u003e\n  \u003c/form\u003e\n\u003c/template\u003e\n\u003cscript\u003e\nlet Form = require('laravel-form-js');\nexport default {\n  props: {\n    url: { type: String, required: true },\n    method: { type: String, required: true },\n    user: {\n      default() {\n        return {\n          name: '',\n          email: ''\n        };\n      }\n    }\n  },\n  data() {\n    return {\n      form: Form.makeFrom(this.user, this.method) // If no method is given, the default is post.\n    }\n  },\n  methods: {\n    submit() {\n      this.form.submit(this.url)\n        .then(response =\u003e {\n        })\n        .catch(error =\u003e {\n          // If it gets here, and there are validation errors, they are automatically set for the form.\n        });\n    }\n  }\n}\n\n\u003c/script\u003e\n```\n\n### Note\nThis library works with the validation of laravel \u003e= 5.5, because now the errors are given like this:\n\n```javascript\n{\n  errors: {\n    name: [],\n    email: []\n  }\n}\n\n```\n## Creating a form\nThere are two ways to create a new form:\n\n```javascript\nForm.makeFrom(data, method = 'post', clearAfterResponse = false);\n// Or\nnew Form(data, method = 'post', clearAfterResponse = false);\n```\n\n## Available Methods\n\nThe methods you can call from the form object are:\n\n- `form.data(dataType)`: Get the form data in a given format. Supported data types: `json`, `form-data`;\n- `form.errorsFor(field)`: Return the errors for the given field. If there are not errors it returns `null`.\n- `form.setMethod(method)`: Change the form method. Supported methods: `post`, `put`, `patch`.\n- `form.submit(url, dataType = 'form-data')`: Submit the form to the given url using the form method and passing the data in the given type. Supported data types: `json`, `form-data`;\n- `form.reset()`: Reset the form to the original data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsantigarcor%2Flaravel-form-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsantigarcor%2Flaravel-form-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsantigarcor%2Flaravel-form-js/lists"}