1

I am using the autocompletev2 search box from blogforce9 to allow users to type a request and have the autocomplete show the closest options. Because autocompletev2 doesn't work with picklists, I had to make a custom setting where each record was the name of a picklist value on the actual object. So basically the options in the autocompletev2 picklist are the names of the custom setting records.

So basically it's set up like this:

- Custom setting records:

Custom Setting Object api Name: "SF_Request_Picklist__c"


Name: "Reassign a territory"

Value_Name__c: "Reassign a territory"

Request_Type__c: Admin


Name: "Create a Field"

Value_Name__c: "Create a Field"

Request_Type__c: Enhancement


etc..

- Actual fields on Request object (hidden on edit/new page):

Custom object api name: "New_SF_Request__c"


Request Options (picklist)

-Values: "Reassign a territory", "Create a Field", etc..


Request Type (picklist)

-Values: "Admin", "Enhancement", etc...


I am trying to make it so that when someone picks a value in the autocomplete search when creating a new request record the value is passed onto the record once it is saved. So if someone chooses "Create a Field" on the autocomplete form, the hidden fields "Request Options" and "Request Type" are automatically filled out once the record is saved. In this case, "Create a Field" in the autocomplete form would select "Create a Field" on the object's select list and also "Enhancement" on the request type picklist.

Here is the relevant code from the visualforce page:

<c:autocompletev2 allowClear="true" syncManualEntry="false" importJquery="true" labelField="Name" 

SObject="SF_Request_Picklist__c" valueField="Value_Name__c" targetField="{!picks}" id="search" 

style="width:60%;align:center"/> 

<apex:actionSupport event="onchange"  rerender="page1" />

And the controller extension:

public with sharing class sfrcon { 

public New_SF_Request__c newreqs {get;set;}

public SF_request_picklist__c pick {get;set;}

public string picks {get;set;}

public sfrcon(ApexPages.StandardController stdController) {

}

}

Anyone have any ideas? We admins need to know each request's type (Admin, Enhancement, etc) and the actual picklist option on the record (Reassign a territory, Create a field, etc)...

Thanks!

0

If I read the code correctly the value they select will be stored in the picks variable.

You need to add an event handler in your page for the onchange event for the input field in the component.

Here is an easy way to do it:

  1. Modify the component to accept an additional parameter which will be the name of the actionfunction to call after the value is selected:

Add to component

<apex:attribute name="functionToCall" type="string" description="The Name of the javaScript function to call on change"/>

function callDeclaredFunction(){

     if(functionToCall.length == 0) return;

      window["{!functionToCall}"]();

}

//For the input field being used or in the JS code for the field
<apex:inputText style="{!Style}" styleClass="auto{!randomJsIden}" value="{!cacheField}"  onchange="callDeclaredFunction()"/>

Then on your main page add:

And Update to this

<c:autocompletev2 allowClear="true" syncManualEntry="false" importJquery="true" labelField="Name" SObject="SF_Request_Picklist__c" valueField="Value_Name__c" targetField="{!picks}" id="search" functionToCall="incomplete_function"/>

What this does is passes the name of the action function to the component which on change of the input text field will call the action function on the main page. Since the variable is already stored in picks you can use the method the action function called to do what you need to with it.

  1. OR you can use jQUERY to attach an on change event handler to the input field and call the action function directly.

There are many ways to do this and these are only 2 examples. Both maintain the functionality of the component. You do not want to modify the component to do the work directly as you would be reducing the portability of the component

  • Thanks for the help! However I am quite new to SFDC development and really have no idea where to go from here. I added all that to the component but don't quite understand where this line would go: //For the input field being used or in the JS code for the field <apex:inputText style="{!Style}" styleClass="auto{!randomJsIden}" value="{!cacheField}" onchange="callDeclaredFunction()"/> Also what would I add to my controller extension and what else would I have to do to make the Request Type and Request Options fields match the selected autocomplete value? Thanks again – Ryan Werner Dec 26 '14 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.