This project has moved and is read-only. For the latest updates, please go here.

SPAutocomplete with Text Filter Webpart

Mar 15, 2014 at 7:22 AM
I'm trying to use the SPAutocomplete function with a Text Filter Webpart to search through text titles in a list. The autocomplete actually works fine however when I select the list item I want to use, the text filter box is momentarily populated and the page auto refreshes to run the filter but it changes the text back to my original text snippet. i.e. it doesn't hold the select text value.

I think the onchange event in the webpart may be fired right before it can use the selected text?

The Sharepoint Webpart code is:
<b>Text Filter</b><br/><input name="ctl00$m$g_a88fe500_10fe_4579_af9e_d6717304b197$SPTextSlicerValueTextControl" type="text" maxlength="255" onchange="SetApplyFiltersToActiveIfPresent();setTimeout('__doPostBack(\'ctl00$m$g_a88fe500_10fe_4579_af9e_d6717304b197$SPTextSlicerValueTextControl\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="ctl00_m_g_a88fe500_10fe_4579_af9e_d6717304b197_SPTextSlicerValueTextControl" style="width:97%;" />
And I just use the following within the ready function to add the title name which works fine:
document.getElementById('ctl00_m_g_a88fe500_10fe_4579_af9e_d6717304b197_SPTextSlicerValueTextControl').title = 'ConcernFilter';
Thank you
Mar 15, 2014 at 2:50 PM
I don't see an call to SPAutocomplete in your code above, but can assume its there.

If you're doing a postback, then SPAutocomplete is going to simply reinitialize upon page reload. It doesn't know anything about your other code, of course.

SPAutocomplete is pretty basic, but gets the job done. If you want more control, look at jQueryUI's autocomplete.

Mar 15, 2014 at 9:15 PM
Marc, thanks for your speedy reply, yes the call is there and works well.

The postback is part of the Sharepoint Text Filter webpart.

I'll check out a few other options.

Thanks AJP
Mar 16, 2014 at 1:19 AM

Just an idea.
Try to store "state" in the URL hash (stuff in front of the #) and see if the postback comes back with that same value in the hash. If so, then you can maybe use it to re-initialize your widget.

Paul T.

-- Sent from Mobile

Mar 16, 2014 at 10:04 AM
Thanks guys, I used a combination of SPGetListItems and jQueryUI's autocomplete, this let me pull extra columns for the drop-down display and also grab the item ID so now I can link each list item directly to their display form page. No need to worry about filters at all now, works great, fast too!