I am developing a VF page where all lookup fields (for both parent & child object) will be replaced by autocomplete/typeahead. It is suggesting perfectly for lookup fields, but can't store the selected value into the database, therefore, the field value for that lookup is empty after creating the record. From the image, typeahead/autosuggestion is working good, but when I select a value, click SAVE button of the page, this lookup field is not filled with the selected value. I have used SELECT2 3.4.2 version to build the autocomplete component, & the reason why field value is not posting is i have used inputText in component controller.
<apex:inputText style="{!Style}" styleClass="auto{!randomJsIden}" value="{!cacheField}" /> <apex:outputPanel id="hiddenPanel"> <apex:inputText value="{!targetField}" id="hiddenField" styleClass="hiddenField{!randomJsIden}" style="display:none"/> </apex:outputPanel> <script>v2{!randomJsIden} = new typeahead{!randomJsIden}({});</script>
I find that a good way to store inputText into database is mentioned here . But, it only works for Sobject (I have sobject where it is not working, I have also List where this technique is throwing error). The component code in the VF page is
<c:TypeAheadComponent allowClear="true" importJquery="true" labelField="Name" SObject="General_Ledge_Account__c" valueField="Id" targetField="{!targetField}" style="width:15rem" />
In summary, I am trying to perform autocomplete for lookup fields in VF page (parent record & multiple children record are creating from this VF page). Autocomplete is fine (collecting data from database), but whatever I am selecting from VF page is not Stored in the database. Any idea how can I use inputText to store/bind user selected data into the backend database?