Sunday, October 6, 2013
Well this one of the most required iteration of my Visualforce Autocomplete Component, which worked well with small data set but starts showing sluggishness with large number of records. After doing some debugging and I felt like the underlying architecture is the problem and needs to be rewritten. And finally while searching for a good JQuery component I came across the Select2 project which looked promising but was a lil but different and was more to do with Picklists. Hmm well gradually I started going deeper into the API and guess what ? I found a way to make it to a Autocomplete component!.
The newer component looked pretty much good and was way faster than the earlier Jquery Autocomplete that I used in V1.
![]() |
| AutocompleteV2 in Action |
Summing up few features of the V2
- The component now uses Select2 instead of Jquery Autocomplete
- Much more faster than earlier version and can handle large dataset
- Complete new UI
- The component no more depends on the Jquery from the package and can use jquery from Visualforce page(if already referred in page).
- Configurable : The search field can be configured to search fields other than "Name" field. Even the value that is returned to controller can be configured return fields other than record Id.
How to Use ?
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="Name" SObject="Account" valueField="Id" targetField="{!targetField}" style="width:200px"/>
Description
- labelField : The field which is displayed in the component and against which matching is done with the entered text. In above code snippet Name is displayed in the autocomplete component.
- valueField : The field value which is passed back to targetfield when a record is selected.
- targetField : The field from controller where the selected values is set.
- SObject : The sobject Api Name against which matching/query is done.
- importJquery : Assign false if you dont want to jquery files from package.
- syncManualEntry : Allow manual entry of data from autocomplete component. So if a matching value is not found for the entered query string, on page submit the same value will be sibmitted to targefield
- allowClear : Set true to give user a option to clear existing value. If this value is set true user will see a small cross Icon to clear the existing value from the field
In addition to this a Visualforce Page "AutocompleteV2Demo" is included in package. This page searches through different accounts that are available in the Org. Have a look at the same for syntax and implementation
Screens
Where can this be used ?
- It can be used for replacing Lookups and Master Detail fields. Instead of pressing the lookup button user can directly type in the autocomplete field to search and link the right record.
- It can not only refer Lookups and Master Details but also can search through any object. It can be used as replacement for picklist. Create a object to store the Values available in picklist and use the V2 component to refer the same.(Recommended only when you have large number picklist values to show)
- Can be used in quick search pages to search for records and swiftly navigate to the record once user submits
Demo And Installation Link /Package http://blogforce9dev-developer-edition.ap1.force.com/ProjectDetail?id=a0290000009KusM





