{"id":22018440,"url":"https://github.com/biohzrdmx/jquery.conditional","last_synced_at":"2025-03-23T09:28:53.326Z","repository":{"id":35901729,"uuid":"40188487","full_name":"biohzrdmx/jQuery.Conditional","owner":"biohzrdmx","description":"Show and hide things depending on the value of other things.","archived":false,"fork":false,"pushed_at":"2015-08-04T14:13:23.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T16:17:24.214Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/biohzrdmx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-04T14:08:17.000Z","updated_at":"2019-04-24T11:32:16.000Z","dependencies_parsed_at":"2022-08-17T20:35:04.901Z","dependency_job_id":null,"html_url":"https://github.com/biohzrdmx/jQuery.Conditional","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biohzrdmx%2FjQuery.Conditional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biohzrdmx%2FjQuery.Conditional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biohzrdmx%2FjQuery.Conditional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biohzrdmx%2FjQuery.Conditional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/biohzrdmx","download_url":"https://codeload.github.com/biohzrdmx/jQuery.Conditional/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245081785,"owners_count":20557843,"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-30T05:12:12.535Z","updated_at":"2025-03-23T09:28:53.293Z","avatar_url":"https://github.com/biohzrdmx.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"jQuery Conditional\n==================\n\nShow and hide things depending on the value of other things.\n\nNow with 100% more HTML5!\n\n### Basic usage ###\n\nBasically, you'll have a `select` element that will have some options for the user to choose from.\n\nThen, you'll have some other controls that you may want to show depending on the selected option from the `select` box.\n\nSo you'll have to add a `data-conditional` attribute to your `select`, give it a meaningful value, say 'foo'.\n\nNow you may want to wrap the conditionally-shown elements in groups, so you can give each group a `data-condition` attribute with the name of the condition (in this case 'foo') and a `data-match` one with the actual value you want to match from the `select`.\n\nCheck the demo below and its source to see how it works.\n\n### Demo source ###\n\t\u003cdiv class=\"form-group\"\u003e\n\t\t\u003clabel for=\"book\" class=\"control-label\"\u003eChoose a book\u003c/label\u003e\n\t\t\u003cselect name=\"book\" id=\"book\" class=\"form-control input-block\" value=\"\" data-conditional=\"book\"\u003e\n\t\t\t\u003coption value=\"\"\u003e\u003c/option\u003e\n\t\t\t\u003coption value=\"Birds from 'Murica\"\u003eBirds from 'Murica\u003c/option\u003e\n\t\t\t\u003coption value=\"They see me rollin'\"\u003eThey see me rollin'\u003c/option\u003e\n\t\t\u003c/select\u003e\n\t\u003c/div\u003e\n\t\u003cdiv class=\"hide conditional-logic\" data-condition=\"book\" data-match=\"Birds from 'Murica\"\u003e\n\t\t\u003cdiv class=\"form-group\"\u003e\n\t\t\t\u003clabel for=\"bird_favorite\" class=\"control-label\"\u003eYour favorite bird was\u003cspan class=\"text-danger\"\u003e*\u003c/span\u003e\u003c/label\u003e\n\t\t\t\u003cinput type=\"text\" name=\"bird_favorite\" id=\"bird_favorite\" class=\"form-control\"\u003e\n\t\t\u003c/div\u003e\n\t\t\u003cdiv class=\"form-group\"\u003e\n\t\t\t\u003clabel for=\"bird_least\" class=\"control-label\"\u003eYour least-favorite bird was\u003cspan class=\"text-danger\"\u003e*\u003c/span\u003e\u003c/label\u003e\n\t\t\t\u003cinput type=\"text\" name=\"bird_least\" id=\"bird_least\" class=\"form-control\"\u003e\n\t\t\u003c/div\u003e\n\t\u003c/div\u003e\n\t\u003cdiv class=\"hide conditional-logic\" data-condition=\"book\" data-match=\"They see me rollin'\"\u003e\n\t\t\u003cdiv class=\"form-group\"\u003e\n\t\t\t\u003clabel for=\"why_hate\" class=\"control-label\"\u003eWhy do you think they're hatin'?\u003cspan class=\"text-danger\"\u003e*\u003c/span\u003e\u003c/label\u003e\n\t\t\t\u003cinput type=\"text\" name=\"why_hate\" id=\"why_hate\" class=\"form-control\"\u003e\n\t\t\u003c/div\u003e\n\t\u003c/div\u003e\n\nAs you can see, its pretty straightforward:\n\n1. Add the `data-conditional` attribute to your `select`\n1. Wrap your conditional elements, add `data-condition` and `data-match` to the wrapper.\n1. Profit!\n\n### Customization ###\n\nYou may want to change the CSS class or the event, heck, you may even want to provide your own toggle logic.\n\nThat's completely possible if you override the `defaults` object inside `$.conditional`\n\nHere's what it looks like:\n\n\t$.conditional = {\n\t\tdefaults: {\n\t\t\tclassName: 'hide',\n\t\t\teventName: 'change',\n\t\t\tonActivate: function(element, opts) {\n\t\t\t\telement.removeClass(opts.className);\n\t\t\t},\n\t\t\tonDeactivate: function(elements, opts, callback) {\n\t\t\t\telements.addClass(opts.className);\n\t\t\t\tcallback.call();\n\t\t\t},\n\t\t\tautoBind: true\n\t\t}\n\t};\n\n### Troubleshooting ###\n\nAs usual, this should work on any _modern_ browser, that means you may run into issues with the crappy, glue-eating ones.\n\nIf you have an idea/fix, please feel free to fork the repo, add your fix/feature and send me a push request.\n\n### License ###\n\nCopyright \u0026copy; 2015 biohzrdmx\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiohzrdmx%2Fjquery.conditional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbiohzrdmx%2Fjquery.conditional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiohzrdmx%2Fjquery.conditional/lists"}