{"id":15510033,"url":"https://github.com/haggen/populous","last_synced_at":"2025-05-10T08:31:06.950Z","repository":{"id":8195005,"uuid":"9625045","full_name":"haggen/populous","owner":"haggen","description":"Populates a \u003cselect\u003e with a remote JSON.","archived":false,"fork":false,"pushed_at":"2016-02-23T01:08:56.000Z","size":28,"stargazers_count":40,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-16T02:01:51.367Z","etag":null,"topics":["ajax","dropdown","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/haggen.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":"2013-04-23T14:27:41.000Z","updated_at":"2023-11-07T12:36:05.000Z","dependencies_parsed_at":"2022-08-06T21:15:59.292Z","dependency_job_id":null,"html_url":"https://github.com/haggen/populous","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haggen%2Fpopulous","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haggen%2Fpopulous/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haggen%2Fpopulous/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haggen%2Fpopulous/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haggen","download_url":"https://codeload.github.com/haggen/populous/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253389726,"owners_count":21900803,"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":["ajax","dropdown","javascript"],"created_at":"2024-10-02T09:45:33.948Z","updated_at":"2025-05-10T08:31:05.883Z","avatar_url":"https://github.com/haggen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Populous\n\n\u003e Populates a `\u003cselect\u003e` with a remote JSON.\n\n## Working Example\n\nhttp://jsfiddle.net/haggen/7tS3e/27/\n\n## Usage\n\n`index.html`:\n```html\n\u003cselect data-source-url=\"options.json\"\u003e\n\n\u003cscript\u003e\n$('select').populous('load');\n\u003c/script\u003e\n```\n\n`options.json`:\n```javascript\n[\"Banana\", \"Apple\", \"Grape\", \"Cranberry\"]\n```\n\nBam! Your `\u003cselect\u003e` now has 4 options: `Banana`, `Apple`, `Grape` and `Cranberry`.\n\n## Configuration\n\nYou can customize the options by providing a hash when calling the plugin, like this:\n\n```javascript\n$('select').populous({...});\n```\n\n### AJAX\n\nTo configure the AJAX request, provide a `source` option with regular [jQuery AJAX settings](http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings):\n\n```javascript\n$('select').populous({\n  source: {\n    url: '/basket',\n    method: 'POST',\n    data: {all: 'fruits'}\n  }\n});\n```\n\nNote that, by default, the method is `GET`, and the URL can be set using the attribute `data-source-url` on the `\u003cselect\u003e` element.\n\n### Mapping the response\n\nPopulous use a `map` function to handle the response.\n\n```javascript\nfunction(response) {\n  return [];\n}\n```\n\nThe resulting array may comprise arrays (pairs of label and value, in that order) or strings (that will be used as both).\n\nBelow is the default `map` option:\n\n```javascript\nfunction(response) {\n  return $.map(response, function(label) {\n    return [[label, label]]; // jQuery#map make it flat, so we add depth\n  });\n}\n```\n\nBut you can provide your own mapping function:\n\n```javascript\n$('select').populous({\n  map: function(response) {\n    return [];\n  }\n});\n```\n\n## API\n\n### Events and states\n\nThere are 2 new events being fired - `loading` and `loaded` - that happens, respectively, right before the AJAX request and right after the `\u003cselect\u003e` is populated with its response.\n\n```javascript\n$('select').on('loading', function() {\n  $(this).attr('disabled', true);\n});\n\n$('select').on('loaded', function() {\n  $(this).attr('disabled', false);\n});\n```\n\nAlso, there's a data property being set to flag when it's loading.\n\n```javascript\nif($('select').data('loading')) {\n  alert('Wait!');\n} else {\n  alert('Ready!');\n}\n```\n\n### Updating value\n\nPopulous does a little patch to allow jQuery's standard method `val` to seamlessly update the `\u003cselect\u003e` even when it isn't finished loading.\n\n```javascript\n$('select').populous('load');\n$('select').val('Hey!'); //=\u003e Will update when finish loading.\n```\n\n### AMD\n\nIf you like [RequireJS](http://requirejs.org) you can easily make a module definition for Populous.\n\n```javascript\ndefine('Populous', ['jquery'], function($) {\n\n  this.jQuery = $;\n\n  // Paste here the contents of populous.js\n\n});\n```\n\n## License\n\nSee [CC Attribution-ShareAlike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/deed.en_US)\n\n## Contribution\n\n1. Fork it\n2. Change it\n3. Commit with brief yet meaningful description\n4. Send pull request\n\nAlso, you could report an issue, help to fix or simply comment in one.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaggen%2Fpopulous","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaggen%2Fpopulous","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaggen%2Fpopulous/lists"}