{"id":21328827,"url":"https://github.com/rdiazv/jquery.form.serializer","last_synced_at":"2025-09-07T21:12:35.866Z","repository":{"id":19793148,"uuid":"23052544","full_name":"rdiazv/jquery.form.serializer","owner":"rdiazv","description":"Simple and powerful form serializations with jQuery","archived":false,"fork":false,"pushed_at":"2014-08-20T04:13:39.000Z","size":436,"stargazers_count":1,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T00:26:06.782Z","etag":null,"topics":[],"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/rdiazv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-17T23:09:18.000Z","updated_at":"2016-01-27T16:18:09.000Z","dependencies_parsed_at":"2022-08-25T02:20:39.954Z","dependency_job_id":null,"html_url":"https://github.com/rdiazv/jquery.form.serializer","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/rdiazv/jquery.form.serializer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdiazv%2Fjquery.form.serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdiazv%2Fjquery.form.serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdiazv%2Fjquery.form.serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdiazv%2Fjquery.form.serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rdiazv","download_url":"https://codeload.github.com/rdiazv/jquery.form.serializer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdiazv%2Fjquery.form.serializer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274095728,"owners_count":25221495,"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","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-21T21:43:16.176Z","updated_at":"2025-09-07T21:12:35.845Z","avatar_url":"https://github.com/rdiazv.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jQuery Form Validation\n\nThis jQuery extension provides an easy way to serialize HTML forms into JSON.\n\nBy default the serialization it's based on the submittable fields according to [W3C Successful controls](http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2), but this is easily customizable to fit your needs.\n\nThe following elements are always ignored:\n\n* Elements without a `name` attribute.\n* File inputs.\n* Buttons.\n\n## Installation\n\nInclude `jquery.form.serializer.min.js` after `jquery.js`.\n\n```html\n\u003cscript type=\"text/javascript\" src=\"jquery.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"jquery.form.serializer.min.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\nBased on a form like this one:\n\n```html\n\u003cform id=\"my-form\"\u003e\n  \u003cinput type=\"hidden\" name=\"token\" value=\"ABC\" /\u003e\n  \u003cinput type=\"text\" name=\"user[name]\" value=\"John Doe\" /\u003e\n  \u003cinput type=\"text\" name=\"user[email]\" value=\"john@email.com\" /\u003e\n  \u003cselect name=\"user[country]\"\u003e\n    \u003coption value=\"CL\" selected\u003eChile\u003c/option\u003e\n  \u003c/select\u003e\n\u003c/form\u003e\n```\n\nSerialize the form into JSON:\n\n```javascript\n$(\"#my-form\").getSerializedForm();\n\n// =\u003e\n{\n  token: \"ABC\",\n  user: {\n    name: \"John Doe\",\n    email: \"john@email.com\",\n    country: \"CL\"\n  }\n}\n```\n\n## Submittable Fields\n\nThe submittable fields are initially selected using:\n\n```javascript\n$.jQueryFormSerializer.submittable = 'input, select, textarea';\n```\n\nThe initial matched set it's reduced passing every function defined in `$.jQueryFormSerializer.filters` to the [filter function](http://api.jquery.com/filter/).\n\nThere are two default filters:\n\n* `enabledOnly`: Disabled fields won't be serialized.\n* `checkedOnly`: Only checked `input[type=\"checkbox\"]` and `input[type=\"radio\"]` will be serialized.\n\n## Value Castings\n\nValue castings are defined in `$.jQueryFormSerializer.castings`, and allows you to preprocess a field value before serializing it.\n\nThe only default value casting it's `booleanCheckbox`, that returns `true` or `false` on checkboxes without an explicit `value` attribute.\n\n## Customization\n\nAny option declared in `$.jQueryFormSerializer` can be overwritten if you need a global customization, or you can pass a hash of options to `getSerializedForm` that will [extend](http://api.jquery.com/jquery.extend/) `$.jQueryFormSerializer`, allowing to change the defaults only for one call.\n\n### Examples\n\nAlways allow disabled fields to be serialized:\n\n```javascript\n$.jQueryFormSerializer.filters.enabledOnly = false;\n```\n\nAllow unchecked fields to be serialized only for this call:\n\n```javascript\n$(\"#my-form\").getSerializedForm({\n  filters: {\n    checkedOnly: false\n  }\n});\n```\n\nAdd a new filter to avoid serializing fields with `.disabled`:\n\n```javascript\n$.jQueryFormSerializer.filters.disabledByClass = function() {\n  return !$(this).hasClass(\"disabled\");\n};\n```\n\nAdd a new value casting for numeric fields:\n\n```javascript\n$(\"#my-form\").getSerializedForm({\n  castings: {\n    numericField: function() {\n      if ($(this).hasClass(\"numeric\")) {\n        return parseInt($(this).val());\n      }\n    }\n  }\n});\n```\n\nThe same applies to `filters`, `castings` and the `submittable` selector.\n\n### Custom Controls\n\nYou can easily integrate any custom control for serialization. For example, given this custom control:\n\n```html\n\u003cform id=\"my-form\"\u003e\n  \u003cdiv class=\"custom-control\" name=\"my-custom-control\" data-custom-value=\"my value\"\u003e\u003c/div\u003e\n\u003c/form\u003e\n```\n\n```javascript\n$.valHooks.custom_control = {\n  get: function(el) {\n    return $(el).data(\"custom-value\");\n  },\n  set: function(el, value) {\n    return $(el).data({ \"custom-value\": value });\n  }\n};\n\n$.fn.customControl = function() {\n  return $(this).each(function() {\n    this.type = \"custom_control\";\n\n    // All your custom control magic...\n  });\n};\n\n$(function() {\n  $(\".custom-control\").customControl();\n});\n```\n\nAdd your custom control to the global configuration:\n\n```javascript\n$.jQueryFormSerializer.submittable += \", .custom-control\"\n```\n\nAnd that's it!\n\n```javascript\n$(\"#my-form\").getSerializedForm(); // =\u003e { \"my-custom-control\": \"my value\" }\n\n$(\".custom-control\").addClass(\"disabled\");\n$(\"#my-form\").getSerializedForm(); // =\u003e {}\n```\n\n## Tests\n\nRun `npm install` and `npm test`, or if you don't have [Node.js](http://nodejs.org/) installed, open `./specs/index.html` on any browser.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdiazv%2Fjquery.form.serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frdiazv%2Fjquery.form.serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdiazv%2Fjquery.form.serializer/lists"}