select2 more examples
This commit is contained in:
parent
49b01353f9
commit
b00407f5b4
37
src/inputs/select2/select2.js
vendored
37
src/inputs/select2/select2.js
vendored
@ -25,6 +25,7 @@ You need initially put both `data-value` and element's text youself:
|
|||||||
<a href="#" id="country" data-type="select2" data-pk="1" data-value="ru" data-url="/post" data-title="Select country"></a>
|
<a href="#" id="country" data-type="select2" data-pk="1" data-value="ru" data-url="/post" data-title="Select country"></a>
|
||||||
<script>
|
<script>
|
||||||
$(function(){
|
$(function(){
|
||||||
|
//local source
|
||||||
$('#country').editable({
|
$('#country').editable({
|
||||||
source: [
|
source: [
|
||||||
{id: 'gb', text: 'Great Britain'},
|
{id: 'gb', text: 'Great Britain'},
|
||||||
@ -35,6 +36,42 @@ $(function(){
|
|||||||
multiple: true
|
multiple: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
//remote source (simple)
|
||||||
|
$('#country').editable({
|
||||||
|
source: '/getCountries'
|
||||||
|
});
|
||||||
|
//remote source (advanced)
|
||||||
|
$('#country').editable({
|
||||||
|
select2: {
|
||||||
|
placeholder: 'Select Country',
|
||||||
|
allowClear: true,
|
||||||
|
minimumInputLength: 3,
|
||||||
|
id: function (item) {
|
||||||
|
return item.CountryId;
|
||||||
|
},
|
||||||
|
ajax: {
|
||||||
|
url: '/getCountries',
|
||||||
|
dataType: 'json',
|
||||||
|
data: function (term, page) {
|
||||||
|
return { query: term };
|
||||||
|
},
|
||||||
|
results: function (data, page) {
|
||||||
|
return { results: data };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
formatResult: function (item) {
|
||||||
|
return item.CountryName;
|
||||||
|
},
|
||||||
|
formatSelection: function (item) {
|
||||||
|
return item.CountryName;
|
||||||
|
},
|
||||||
|
initSelection: function (element, callback) {
|
||||||
|
return $.get('/getCountryById', { query: element.val() }, function (data) {
|
||||||
|
callback(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
**/
|
**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user