{"id":19555026,"url":"https://github.com/kanety/jquery-nested-form","last_synced_at":"2025-04-26T22:32:00.998Z","repository":{"id":57123845,"uuid":"160005808","full_name":"kanety/jquery-nested-form","owner":"kanety","description":null,"archived":false,"fork":false,"pushed_at":"2021-08-21T13:17:57.000Z","size":51,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-31T17:45:39.075Z","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/kanety.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":"2018-12-02T02:17:05.000Z","updated_at":"2022-12-29T00:08:02.000Z","dependencies_parsed_at":"2022-08-29T03:51:46.544Z","dependency_job_id":null,"html_url":"https://github.com/kanety/jquery-nested-form","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanety%2Fjquery-nested-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanety%2Fjquery-nested-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanety%2Fjquery-nested-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanety%2Fjquery-nested-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanety","download_url":"https://codeload.github.com/kanety/jquery-nested-form/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224048631,"owners_count":17247056,"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":[],"created_at":"2024-11-11T04:31:06.293Z","updated_at":"2024-11-11T04:31:29.604Z","avatar_url":"https://github.com/kanety.png","language":"JavaScript","readme":"# jquery-nested-form\n\nA jquery plugin for adding / removing Rails nested form dynamically.\n\n## Dependencies\n\n* jquery\n\n## Installation\n\nInstall from npm:\n\n    $ npm install @kanety/jquery-nested-form --save\n\n## Usage\n\nBuild nested form using Rails `fields_for` as usual:\n\n```erb\n\u003c%= form_with do |f| %\u003e\n  \u003cdiv id=\"container\"\u003e\n    \u003c%= f.fields_for :assocs do |assoc_form| %\u003e\n      \u003cdiv class=\"nested-form\"\u003e\n        \u003c%= assoc_form.text_field :text %\u003e\n        \u003cbutton type=\"button\" class=\"remove\"\u003eRemove\u003c/button\u003e\n      \u003c/div\u003e\n    \u003c% end %\u003e\n    \u003cbutton type=\"button\" id=\"add\"\u003eAdd\u003c/button\u003e\n  \u003c/div\u003e\n\u003c% end %\u003e\n```\n\nThen run:\n\n```javascript\n$('#container').nestedForm({\n  forms: '.nested-form',\n  adder: '#add',\n  remover: '.remove',\n  associations: 'assocs'\n});\n```\n\nNew nested form is added when the `#add` button is clicked.\nThe last elements of the `.nested-form` are used as a template to be added.\nThe index of `id` and `name` attributes are incremented automatically.\n\n```html\n\u003cform\u003e\n  \u003cdiv id=\"container\"\u003e\n    \u003cdiv class=\"nested-form\"\u003e\n      \u003cinput type=\"text\" name=\"model[assocs_attributes][0][text]\" id=\"model_assocs_attributes_0_text\"\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"nested-form\"\u003e\n      \u003cinput type=\"text\" name=\"model[assocs_attributes][1][text]\" id=\"model_assocs_attributes_1_text\"\u003e\n    \u003c/div\u003e\n    \u003cbutton type=\"button\" id=\"add\"\u003eAdd\u003c/button\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n### Options\n\n`associations` and `postfixes` are available for finding the index of the nested form.\nIf your nested form consists of multiple associations such as `assocsA` and `assocsB`, you can set the associations as the following example:\n\n```javascript\n$().nestedForm({\n  associations: ['assocsA', 'assocsB'],\n  postfixes: '_attributes'\n});\n```\n\n`tags` and `attributes` are available to customize the attributes to be replaced:\n\n```javascript\n$().nestedForm({\n  tags: $.NestedForm.getDefaults().tags.concat(['a']),\n  attributes: $.NestedForm.getDefaults().attributes.concat(['onclick'])\n});\n```\n\n`max` is useful if you want to disable the add button when the number of nested forms reached to the limit:\n\n```javascript\n$().nestedForm({\n  max: 10\n});\n```\n\n### Callbacks\n\nFollowing callbacks are available to manipulate DOM elements:\n\n```javascript\n$().nestedForm({\n  afterInitialize: function(instance) {},\n  onBuildForm: function($form) {},\n  beforeAddForm: function($container, $form) {},\n  afterAddForm: function($container, $form) {},\n  beforeRemoveForm: function($form) {},\n  afterRemoveForm: function($form) {}\n});\n```\n\n### Multi-level nested form\n\nIf you have multi-level nested form, use `nestedForm` as follows:\n\n```erb\n\u003c%= form_with do |f| %\u003e\n  \u003cul id=\"container\"\u003e\n    \u003c%= f.fields_for :assocs do |assoc_form| %\u003e\n      \u003cli class=\"nested-form\"\u003e\n        \u003c%= assoc_form.text_field :text %\u003e\n        \u003cul class=\"deep-container\"\u003e\n          \u003c%= assoc_form.fields_for :assocs2 do |assoc2_form| %\u003e\n            \u003cli class=\"deep-nested-form\"\u003e\n              \u003c%= assoc2_form.text_field :text %\u003e\n            \u003c/li\u003e\n          \u003c% end %\u003e\n          \u003cli\u003e\u003cbutton type=\"button\" class=\"deep-add\"\u003eAdd\u003c/button\u003e\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/li\u003e\n    \u003c% end %\u003e\n    \u003cli\u003e\u003cbutton type=\"button\" class=\"add\"\u003eAdd\u003c/button\u003e\u003c/li\u003e\n  \u003c/ul\u003e\n\u003c% end %\u003e\n```\n\n```javascript\n$('#container').nestedForm({\n  forms: '.nested-form',\n  adder: '.add',\n  nestedForm: {\n    forms: '.deep-nested-form',\n    adder: '.deep-add'\n  }\n});\n```\n\nThe `nestedForm` option handles same arguments as the first-level form.\n\n## License\n\nThe library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanety%2Fjquery-nested-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanety%2Fjquery-nested-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanety%2Fjquery-nested-form/lists"}