But when I build the ajax, the value being embedded from the first select is undefined. Any thoughts?
$(".select2-foos").select2({
minimumInputLength: 3
, allowClear: true
, ajax: {
url: "/api/v1/foos"
, dataType: 'json'
, type: 'GET'
, delay: 250
, data: function(params) {
return {
search: params.term
, page: 10
};
}
, processResults: function(data, page) {
// parse the results into the format expected by Select2. Since
// we are using custom formatting functions we do not need to
// alter the remote JSON data
return { results: $.map(data, function(d, i) {
return { id: d.foo_id, text: d.foo_name }
})
};
}
, cache: true
}
, escapeMarkup: function(markup) { return markup; } // let our custom formatter work
, theme: "bootstrap"
, placeholder: "Please select a foo"
});
$(".select2-boos").select2({
minimumInputLength: 3
, allowClear: true
, ajax: {
url: function(params) {
return '/api/v1/foos/' + $('select2-foos').val() + '/boos';
}
, dataType: 'json'
, type: 'GET'
, delay: 250
, data: function(params) {
return {
search: params.term // search term
, page: 10
};
}
, processResults: function(data, page) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return { results: $.map(data, function(d, i) {
return { id: d.boo_id, text: d.boo_name }
})
};
}
, cache: true
}
, escapeMarkup: function(markup) { return markup; } // let our custom formatter work
, theme: "bootstrap"
, placeholder: "Please select a boos"
});
--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at https://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.