Skip to content

Commit

Permalink
improve "load once" example
Browse files Browse the repository at this point in the history
  • Loading branch information
oyejorge committed Sep 28, 2020
1 parent 393e527 commit 0345c0a
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 13 deletions.
154 changes: 154 additions & 0 deletions doc_src/js/states.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"states": [
{
"text": "Alabama"
},
{
"text": "Alaska"
},
{
"text": "Arizona"
},
{
"text": "Arkansas"
},
{
"text": "California"
},
{
"text": "Colorado"
},
{
"text": "Connecticut"
},
{
"text": "Delaware"
},
{
"text": "Florida"
},
{
"text": "Georgia"
},
{
"text": "Hawaii"
},
{
"text": "Idaho"
},
{
"text": "Illinois"
},
{
"text": "Indiana"
},
{
"text": "Iowa"
},
{
"text": "Kansas"
},
{
"text": "Kentucky"
},
{
"text": "Louisiana"
},
{
"text": "Maine"
},
{
"text": "Maryland"
},
{
"text": "Massachusetts"
},
{
"text": "Michigan"
},
{
"text": "Minnesota"
},
{
"text": "Mississippi"
},
{
"text": "Missouri"
},
{
"text": "Montana"
},
{
"text": "Nebraska"
},
{
"text": "Nevada"
},
{
"text": "New Hampshire"
},
{
"text": "New Jersey"
},
{
"text": "New Mexico"
},
{
"text": "New York"
},
{
"text": "North Carolina"
},
{
"text": "North Dakota"
},
{
"text": "Ohio"
},
{
"text": "Oklahoma"
},
{
"text": "Oregon"
},
{
"text": "Pennsylvania"
},
{
"text": "Rhode Island"
},
{
"text": "South Carolina"
},
{
"text": "South Dakota"
},
{
"text": "Tennessee"
},
{
"text": "Texas"
},
{
"text": "Utah"
},
{
"text": "Vermont"
},
{
"text": "Virginia"
},
{
"text": "Washington"
},
{
"text": "West Virginia"
},
{
"text": "Wisconsin"
},
{
"text": "Wyoming"
}
]
}
21 changes: 8 additions & 13 deletions doc_src/pages/examples/remote.njk
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ tomSelect('#select-repo',{
if (!query.length) return callback();
$.ajax({
url: 'https://api.github.com/search/repositories?q=' + encodeURIComponent(query),
type: 'GET',
error: function() {
callback();
},
Expand Down Expand Up @@ -95,25 +94,22 @@ tomSelect('#select-repo',{
<script>
{% set script %}
tomSelect('#select-state',{
valueField: 'name',
labelField: 'name',
searchField: 'name',
render: {
option: function(item, escape) {
return `<div>${ escape(item.name) }</div>`;
}
},
valueField: 'text',
load: function(query, callback) {
this.settings.load = null;
var self = this;
if( self.loading > 1 ){
callback();
return;
}
$.ajax({
url: 'https://cdn.jsdelivr.net/gh/CoreyMSchafer/code_snippets/Python-JSON/states.json',
type: 'GET',
url: '/js/states.json',
error: function() {
callback();
},
success: function(res) {
callback(res.states);
self.settings.load = null;
}
});
}
Expand Down Expand Up @@ -206,7 +202,6 @@ tomSelect('#select-repo2',{
if (!query.length) return callback();
$.ajax({
url: 'https://api.github.com/search/repositories?q=' + encodeURIComponent(query),
type: 'GET',
error: function() {
callback();
},
Expand Down

0 comments on commit 0345c0a

Please sign in to comment.