I'm using SPAutocomplete from SPServices because I have a requirement to make a searchable lookup field rather than an OOTB lookup field (drop down menu), as there is potential for thousands of values in the source column. It's working fine, except it's displaying "string;#" before the value, and I need only the value to appear for each list item.
Here is my code:
<script
src="https://code.jquery.com/jquery-3.3.1.js"
type=text/javascript>
</script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.js">
type=text/javascript>
</script>
<script type="text/javascript">
$(document).ready(function () {
$().SPServices.SPAutocomplete({
sourceList: "{C9AF367D-2CA1-40EE-B0AE-99CFDSAF6543389}",
sourceColumn: "Reported_x0020_Tracking_x0020_Number",
columnName: "Tracking Number",
ignoreCase: true,
filterType: "Contains",
numChars: 1,
uniqueVals: true,
slideDownSpeed: 'fast'
});
$("input[id^='_x0074_wj5']").keyup(function() {
var ul = document.getElementById("SPAutocomplete__x0074_wj5");
var items = ul.getElementsByTagName("li");
for (var i = 0; i < items.length; ++i) {
items[i].JSON.stringify(items[i]);
items[i].substring(9,21);
}
});
});
</script>
The HTML:
<ul id="SPAutocomplete__x0074_wj5" style="width: 385.99px; padding: 2px; border: 1px solid rgb(42, 31, 170); background-color: rgb(255, 255, 255); position: absolute; z-index: 40; margin: 0px;">
<li style="display: block; position: relative; cursor: inherit; color: rgb(68, 68, 68); background: transparent;">string;#RVFUF19-0000</li>
<li style="display: block; position: relative; cursor: inherit; color: rgb(68, 68, 68); background: transparent;">string;#RVFUF19-0001</li>
<li style="display: block; position: relative; cursor: inherit; color: rgb(68, 68, 68); background: transparent;">string;#RVFUF19-0002</li>
<li style="display: block;position: relative;cursor: pointer;">string;#RVFUF19-0003</li>
<li style="display: block;position: relative;cursor: pointer;">string;#RVFUF19-0004</li>
<li style="display: block;position: relative;cursor: pointer;">string;#RVFUF19-0005</li>
<li style="display: block;position: relative;cursor: pointer;">string;#RVFUF19-0006</li></ul>
The keyup function is firing, but I can't get it to display only the substring I want from the list items. I am beginner level with JQuery (actually a data scientist - but have been required to create custom lists for data collection purposes).
Any help is greatly appreciated!