Sha256: 27da49bb754b95912673b78df3179a2afb96be27f844a8f220beaaee67e56422
Contents?: true
Size: 1.08 KB
Versions: 46
Compression:
Stored size: 1.08 KB
Contents
<%= pb_rails("typeahead", props: { async: true, load_options: 'asyncPillsPromiseOptions', label: "Github Users", name: :foo, pills: true, placeholder: "type the name of a Github user" }) %> <!-- This section is an example of how to provide load_options prop for using dynamic options --> <%= javascript_tag defer: "defer" do %> // Simple filter function, providing a list of results in the expected data format const filterResults = function(results) { return results.items.map(function(result) { return { label: result.login, value: result.id, } }) } /* Note: Make sure you assign this to window or a namespace within window or it will not be accessible to the kit! */ window.asyncPillsPromiseOptions = function(inputValue) { return new Promise(function(resolve) { if (inputValue) { fetch(`https://api.github.com/search/users?q=${inputValue}`) .then(function(response) { return response.json() }) .then(function(results) { resolve(filterResults(results))}) } else { resolve([]) } }) } <% end %>
Version data entries
46 entries across 46 versions & 1 rubygems