All Projects → haggen → Populous

haggen / Populous

Populates a <select> with a remote JSON.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Populous

React Selectrix
A beautiful, materialized and flexible React Select control
Stars: ✭ 166 (+315%)
Mutual labels:  ajax, dropdown
Render async
render_async lets you include pages asynchronously with AJAX
Stars: ✭ 974 (+2335%)
Mutual labels:  ajax
Lmdropdownviewswift
LMDropdownViewSwift is a simple dropdown view inspired by Tappy.
Stars: ✭ 18 (-55%)
Mutual labels:  dropdown
Rext
🎈A lightweight (< 5kb gzipped) and Promise-supported HTTP request library, for all browsers.
Stars: ✭ 14 (-65%)
Mutual labels:  ajax
Form Js
Easily create web forms. Supports Meteor, AngularJS, React, Polymer and any CSS library, e.g. Bootstrap.
Stars: ✭ 9 (-77.5%)
Mutual labels:  dropdown
Error Report
前端异常上报
Stars: ✭ 20 (-50%)
Mutual labels:  ajax
Push State
Turn static web sites into dynamic web apps.
Stars: ✭ 16 (-60%)
Mutual labels:  ajax
Ajax
ajax without jquery
Stars: ✭ 40 (+0%)
Mutual labels:  ajax
Nb Choices
Angular wrapper for choices.js, vanilla, lightweight, configurable select box/text input plugin
Stars: ✭ 32 (-20%)
Mutual labels:  dropdown
Infinite Scroll
📜 Automatically add next page
Stars: ✭ 7,006 (+17415%)
Mutual labels:  ajax
Xhr.js
🌎 xhr.js is a library(< 2Kb) to make AJAX/HTTP requests with XMLHttpRequest.
Stars: ✭ 12 (-70%)
Mutual labels:  ajax
Javascript ninja
javascript-ninja 😆
Stars: ✭ 11 (-72.5%)
Mutual labels:  ajax
React Native Number Please
🔢 Generate react-native pickers with range numbers.
Stars: ✭ 30 (-25%)
Mutual labels:  dropdown
Re Spinner
A spinner that supports item click events
Stars: ✭ 19 (-52.5%)
Mutual labels:  dropdown
Searchtextfield
UITextField subclass with autocompletion suggestions list
Stars: ✭ 980 (+2350%)
Mutual labels:  dropdown
Ironwing
universal, framework agnostic, transport layer
Stars: ✭ 17 (-57.5%)
Mutual labels:  ajax
Vanilla Select
Standalone replacement for select boxes.
Stars: ✭ 12 (-70%)
Mutual labels:  dropdown
Load.js
Dynamically loading external JavaScript and CSS files
Stars: ✭ 15 (-62.5%)
Mutual labels:  ajax
Spring Web Rss Channels
A Full Stack RSS Reader web application built with Spring MVC and JSP. It uses libraries like Spring, JPA, Bootstrap, Apache Tiles, JSP etc. There is also a static code analysis tool called Checkstyle.
Stars: ✭ 40 (+0%)
Mutual labels:  ajax
Ecommerce
We're going to take you step-by-step to build a modern, fully open-source, eCommerce web application using Python, Django, Bootstrap, Javascript, and more.
Stars: ✭ 980 (+2350%)
Mutual labels:  ajax

Populous

Populates a <select> with a remote JSON.

Working Example

http://jsfiddle.net/haggen/7tS3e/27/

Usage

index.html:

<select data-source-url="options.json">

<script>
$('select').populous('load');
</script>

options.json:

["Banana", "Apple", "Grape", "Cranberry"]

Bam! Your <select> now has 4 options: Banana, Apple, Grape and Cranberry.

Configuration

You can customize the options by providing a hash when calling the plugin, like this:

$('select').populous({...});

AJAX

To configure the AJAX request, provide a source option with regular jQuery AJAX settings:

$('select').populous({
  source: {
    url: '/basket',
    method: 'POST',
    data: {all: 'fruits'}
  }
});

Note that, by default, the method is GET, and the URL can be set using the attribute data-source-url on the <select> element.

Mapping the response

Populous use a map function to handle the response.

function(response) {
  return [];
}

The resulting array may comprise arrays (pairs of label and value, in that order) or strings (that will be used as both).

Below is the default map option:

function(response) {
  return $.map(response, function(label) {
    return [[label, label]]; // jQuery#map make it flat, so we add depth
  });
}

But you can provide your own mapping function:

$('select').populous({
  map: function(response) {
    return [];
  }
});

API

Events and states

There are 2 new events being fired - loading and loaded - that happens, respectively, right before the AJAX request and right after the <select> is populated with its response.

$('select').on('loading', function() {
  $(this).attr('disabled', true);
});

$('select').on('loaded', function() {
  $(this).attr('disabled', false);
});

Also, there's a data property being set to flag when it's loading.

if($('select').data('loading')) {
  alert('Wait!');
} else {
  alert('Ready!');
}

Updating value

Populous does a little patch to allow jQuery's standard method val to seamlessly update the <select> even when it isn't finished loading.

$('select').populous('load');
$('select').val('Hey!'); //=> Will update when finish loading.

AMD

If you like RequireJS you can easily make a module definition for Populous.

define('Populous', ['jquery'], function($) {

  this.jQuery = $;

  // Paste here the contents of populous.js

});

License

See CC Attribution-ShareAlike 4.0 International

Contribution

  1. Fork it
  2. Change it
  3. Commit with brief yet meaningful description
  4. Send pull request

Also, you could report an issue, help to fix or simply comment in one.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].