[html]
<input style="width: 200px;" type = 'text' data-init-text = '$this->item_code' value = '$this->item_code' name = 'item_code' id = 'item_code' />
[javascript]
function itemCodeAutoComplete(){
$("#item_code").select2({
placeholder: "Search for a Item",
minimumInputLength: 1,
id : function(priv) {
return priv.code;
},
ajax: {
url: 'autocomplete.php?action=item&type=s&bpartner_id='+$('#bpartner_id').val()+"&category_id="+$('#category_id').val()+"&warehouse_id="+$('#warehouse_id').val(),
dataType: 'json',
quietMillis: 250,
data: function (term, page) {
return {
q: term, // search term
};
},
results: function (data, page) {
return { results: data.items };
}
},
initSelection: function(element, callback) {
var elementText = $(element).attr('data-init-text');
elementText = "test";
var data = [{id: elementText , text:elementText}];
callback(data);
},
formatResult: function(data) {
var markup = '<div class="row-fluid">' +
'<div class="span2" >'+data.label+'</div></div>';
return markup;
},
formatSelection: function(data){
$('#item_name').val(data.label_name);
$('#uom_id').val(data.label_uomid);
$('#unit_price').val(data.label_unitprice);
$('#item_id').val(data.id);
return data.value;
},
});
Cannot do a auto display text => "test" and also callback is not working.
`problem solve. now i know callback(data); mean go to my formatSelection(data), so inside data.value field need same with initSelection field
because formatselection return data.value; so in initSelection aslo need to set text become value callback(data); },`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.