How can I add autocomplete to a textfilter webpart which keeps the mouse selected value as the textbox value?
With the current code user start typing then autocomplete list brings up but once he/she wants to select item the typed in characters are reverted.
The code works perfectly if the user selects with the keyboard.
I think the problem could be how text filter postback is using data entered, could that information be stored and later reused hence not using the selected item?
Please give a note if I need to provide more information.
Code:
<script>
$(document).ready(function(){
var itemSource = [];
var controlID = "ctl00_m_g_2ef45d15_c8c2_48ad_a3d4_37666031bae7_SPTextSlicerValueTextControl";
var externalParties = [];
$().SPServices({
operation: "GetListItems",
listName: "List1",
async: false,
completefunc: function(xData, Status){
$(xData.responseXML).SPFilterNode("z:row").each(function(){
externalParties.push($(this).attr("ows_Owner"));
});
}
});
$('input[id^=' + controlID + ']').autocomplete({
source: externalParties,
minLength: 1,
select: function(event, ui){
var origEvent = event;
while (origEvent.originalEvent !== undefined){
origEvent = origEvent.originalEvent;
}
if (origEvent.type == 'click'){
document.getElementById(controlID).value = ui.item.value
return false;
} else {
};
return false;
}
});
});
</script>
Edit: the problem seems to be with the __doPostBack function. If I turn it off:
$('input[id^=' + controlID + ']').attr('onchange',null)
It keeps the selected value however will not trigger the dopostback function. Trying to replace the dopostback then with this works:
$('input[id^=' + controlID + ']').attr('onchange',null).change(function(){setTimeout(__doPostBack(controlID, document.getElementById(controlID).value), 0);});
however it is doing the same - reverts to the original value. Please help how to tweak the postback then to use the selected value? Thanks!
clickevent. Why have you?