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

SPServices.Autocomplete + JQuery + Infopath 2010

Jan 6, 2012 at 2:07 PM


I'm trying to implement an autocomplete function which will be bound to a text field on an infopath 2010 form.  The code I have so far is:


<script type="text/javascript" src="/Scripts Library/jquery.min.js"></script>
<script type="text/javascript" src="/Scripts Library/jquery.SPServices-0.5.8.min.js"></script>

<script type="text/javascript">

	var supplierID;
	var camlQuery;
	var $j = jQuery.noConflict();

	// Needed because it's an infopath form which is being loaded asyncronously
window.onload = function() { window.setTimeout(readyCall, 2000); } function readyCall(){ // Set Title Attribute Of The Description Text Field $j("#ctl00_m_g_85881f76_adb1_4b23_b83f_763612264bee_FormControl0_V1_I1_R10_I1_T3").attr('title','partDesc'); // Works // Set The Focus On The SupplierID Field $j("#ctl00_m_g_85881f76_adb1_4b23_b83f_763612264bee_FormControl0_V1_I1_D1").focus(); // Works // This is where it's going wrong $j("#ctl00_m_g_85881f76_adb1_4b23_b83f_763612264bee_FormControl0_V1_I1_D1").bind('change',function (){ supplierID = $j("#ctl00_m_g_85881f76_adb1_4b23_b83f_763612264bee_FormControl0_V1_I1_D1").val(); alert(supplierID); camlQuery = "<Eq><FieldRef Name='supplierID'/><Value Type='Number'>" + supplierID + "</Value></Eq>"; $j().SPServices.SPAutocomplete({ sourceList: "parts", sourceColumn: "description", columnName: "partDesc", CAMLQuery: camlQuery, numChars: 3, ignoreCase: true, highlightClass: "ms-bold", slideDownSpeed: 100, debug: true }); }); } </script>

Ideally the camlQuery should change every time the supplierID is changed, and the autocomplete function should refresh and lookup the parts for that supplier.  My problem is that this code fires once, then after that is never fires again.  I've tried taking the $j.SPServices call out of readyCall and placing it at the top / bottom of the javascript code block, and then it never fires.  What am I doing wrong.  Any help offered greatly appreciated.




Jan 6, 2012 at 5:25 PM


I've done this in the past and I have a post on it. See if that gets you over the hump. If not, feel free to post back.