Skip to content

Instantly share code, notes, and snippets.

@DOOMer
Created July 10, 2014 16:32
Show Gist options
  • Save DOOMer/b2250a729852b5b2c29f to your computer and use it in GitHub Desktop.
Save DOOMer/b2250a729852b5b2c29f to your computer and use it in GitHub Desktop.
Fancy fields select append list options from JSON
{% verbatim %}
<script type="text/javascript">
$("#id_model_auto").fancyfields();
$("#id_auto_vendor_select").fancyfields({
onSelectChange: function (input,text,val){
console.log("Current input - ID : "+input.attr("id") + " , selected text : " + text + " , value : " + val);
var url = "/classifieds/auto-liist/" + val + "/";
$("#id_model_auto").fancyfields("clean");
$.getJSON(url,
function(data){ // заполняем
var $models_list = $('#id_model_auto');
$models_list.empty();
$models_list.append(
$('<option>', {text: ''})
)
var listOptions = []
$.each(data['cars'], function(v, n){
console.log(v);
console.log(n);
listOptions.push([n, v]);
//$models_list.append(
//$('<option>', {text: n, value: v})
//);
});
$("#id_model_auto").setOptions(listOptions);
});
}
});
</script>
{% endverbatim %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment