-
-
Save Fire-Dragon-DoL/5993136 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"total": 8084, | |
"results": [ | |
{ | |
"cap": 35031, | |
"id": 8085, | |
"name": "Abano Terme", | |
"province": "PD", | |
"state_id": 25 | |
}, | |
{ | |
"cap": 26834, | |
"id": 8086, | |
"name": "Abbadia Cerreto", | |
"province": "LO", | |
"state_id": 21 | |
} | |
], | |
"more": false | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var $; | |
$ = jQuery; | |
$(function() { | |
$('a.submit-link').on('click', function(ev) { | |
ev.preventDefault(); | |
$(this).closest('form').submit(); | |
}); | |
$('.spinner-float').spinner({ | |
step: 0.01, | |
numberFormat: 'n', | |
min: 0 | |
}); | |
$('.spinner').spinner({ | |
min: 0 | |
}); | |
$('.select2-cities').select2({ | |
width: 200, | |
minimumInputLength: 1, | |
dropdownCssClass: 'bigdrop', | |
loadMorePadding: 300, | |
formatResult: function(obj, container, query, escapeMarkup) { | |
console.log("formatResult"); | |
return obj.name; | |
}, | |
formatSelection: function(obj, container) { | |
console.log("formatSelection"); | |
return obj.name; | |
}, | |
initSelection: function(element, callback) { | |
var id; | |
console.log("initSelection"); | |
id = $(element).val(); | |
if ((id != null) && id !== '') { | |
$.ajax(gon.cities_path + '/' + id + '.json', { | |
dataType: 'jsonp' | |
}).done(function(data) { | |
console.log("initSelection callback"); | |
console.log(data); | |
callback(data); | |
}); | |
} | |
}, | |
ajax: { | |
url: gon.cities_path + '.json', | |
dataType: 'jsonp', | |
data: function(term, page) { | |
return { | |
query: term, | |
page: page - 1 | |
}; | |
}, | |
results: function(data, page) { | |
console.log("results"); | |
console.log(data); | |
return data; | |
} | |
} | |
}); | |
}); | |
}).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ... --> | |
<script type="text/javascript"> | |
//<![CDATA[ | |
window.gon = {};gon.cities_path="http://localhost:3000/cities"; | |
//]]> | |
</script> | |
<!-- ... --> | |
<input class="select2-cities" id="travel_diary_city_id" name="travel_diary[city_id]" type="hidden" value="13987" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment