I have a jquery autocomplete that is "working" only if I hardcode an array in javascript.
Here's what's happening. Type__c is a picklist. Once I change the picklist, I call a method in my extension that populates myList. I then want to use myList as the source for the autocomplete. I think I'm missing some steps here because after the method is called and myList has values in the controller, it's blank when I do console.log on myArr (commented out line).
Another issue is, even if I hardcode values into myList in the extension, it doesn't work with the autocomplete for some reason. The log shows it has values but autocomplete won't work. However, autocomplete works just fine with the hardcoded javascript array. Is it because javascript arrays are different? It seem to have quotes around it when hardcoded.
<script type="text/javascript">
var j$ = jQuery.noConflict();
var myArr = ['India', 'USA', 'China','FInland','Norway','Netherlands'];
//var myArr ='{!myList}';
j$(document).ready(function(){
j$(".inputid").autocomplete({
source : myArr
});
});
</script>
<apex:pageBlockSection id="topsection" columns="1">
<apex:inputField value="{!myObject.Type__c}" onChange="populateList()"/>
<apex:inputField styleClass="inputid" id="itemname" value="{!myObject.Item_Name__c}"/>
<apex:inputField value="{!myObject.Action__c}"/>
</apex:pageBlockSection>
EDIT: populateList() is already using an actionfunction and is working fine. Just didn't include it here.