0
<apex:pageBlock title="Account Edit" >
<apex:pageBlockButtons >
<apex:commandButton value="save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1" title="Account Information" >

<apex:inputField value="{!acc.Name}" id="apexaccountautocomplete"/>
<apex:inputField value="{!Account.Phone}" id="apexaccountphoneautocomplete"/>


 </apex:pageBlockSection>
 <apex:pageBlockSection columns="1" title="Address Information">
 <apex:inputField value="{!Account.BillingCity}" id="apexaccountcityautocomplete"/>
  <apex:inputField value="{!Account.BillingPostalCode}" id="apexaccountcitycodeautocomplete"/>
<apex:inputText value="{!acc.Name}" required="true"/>
 </apex:pageBlockSection>

 </apex:pageBlock>

public class AutoCompleteDemoController{
public Account  acc{
        get{
        system.debug('check'+acc.Name);
        return acc;}
        set{

        }
    } 
public Account sample;
    public Account noiseDictionary { get; set; }

    public AutoCompleteDemoController(ApexPages.StandardController stdcontroller) {

    }

    public list<account> getAccountList(){
        system.debug('sddd'+acc.Name);
        return [SELECT Name FROM Account WHERE Name LIKE '%s%' limit 5];
    }
    public list<account> getAccountphoneList(){
        return [select id,phone,Name,BillingPostalCode,BillingCity from account limit 5];
    }
    public list<account> getAccountcityList(){
        return [select id,phone,Name,BillingPostalCode,BillingCity from account limit 5];
    }
    public list<account> getAccountcitycodeList(){
        return [select id,phone,Name,BillingPostalCode,BillingCity from account limit 5];
    }
}

I am not not to get the field value using getter and setter,i dont want to refresh my page in any point of time.need your help to get the value from vf page to controller.thanks in advance.

2
  • What exactly do you want to do here?
    – Saroj Bera
    Commented Nov 3, 2016 at 6:00
  • autocomplete functionality.i want to fetch the records based on value of inputfield.
    – Satya
    Commented Nov 3, 2016 at 6:17

1 Answer 1

0

In the example below, I have just written some code in jQuery, JavaScript Remoting using Remoting in Apex and Visualforce page. It works based on jQuery UI autocomplete feature. I am choosing an account and sending the selected account to the server to get the Account details like Phone, City and Zip. Hope this helps.

VF Page

<apex:page standardController="Account" extensions="AutoCompleteDemoController">
    <script src="https://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css"/>
    <apex:form id="searchform">
        <apex:pageBlock title="Account Edit" id="searchblk" >
            <apex:pageBlockButtons >
                <apex:commandButton value="save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1" title="Account Information" id="searchblkscn" >
                <apex:inputText value="{!Account.Name}" id="name"/>
                <apex:inputText value="{!Account.Phone}" id="phone"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection columns="1" title="Address Information">
                <apex:inputText value="{!Account.BillingCity}" id="city"/>
                <apex:inputText value="{!Account.BillingPostalCode}" id="zip"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <script type="text/javascript">
        if(typeof jQuery != 'undefined'){
            j$ =jQuery.noConflict();
        }
        j$(document).ready(function(){
            j$('[id*="name"]').autocomplete({
                source: function(request, response) {
                    Visualforce.remoting.Manager.invokeAction(
                        '{!$RemoteAction.AutoCompleteDemoController.getAccountList}',
                        request.term,
                        function(result, event){
                            if (event.status) {
                                var objList = [];
                                for(var i = 0; i < result.length; i++){
                                    var obj = new Object();
                                    obj.label = result[i].Name;
                                    obj.value = result[i].Name;
                                    obj.id = result[i].Id;
                                    obj.Phone = result[i].Phone;
                                    obj.BillingCity = result[i].BillingCity;
                                    obj.BillingPostalCode = result[i].BillingPostalCode;
                                    objList.push(obj);
                                }
                                response(objList);                              
                            }else{
                                alert(event.message);
                            }
                        },
                        {escape: true}
                    );
                },
                select: function(event, ui){
                    j$('[id*="name"]').val(ui.item.value);
                    j$('[id*="phone"]').val(ui.item.Phone); 
                    j$('[id*="city"]').val(ui.item.BillingCity);
                    j$('[id*="zip"]').val(ui.item.BillingPostalCode);                    
                    return false;
                }               
            });
        });  
    </script>    
</apex:page>

Apex Controller

public class AutoCompleteDemoController{
    public String accName{get;set;}
    public String accPhone{get;set;}

    public AutoCompleteDemoController(ApexPages.StandardController stdcontroller) {

    }
    @RemoteAction
    public static list<Account> getAccountList(string s){
        list<Account> accList = new list<Account>();
        if(s != ''){
            accList = [SELECT Id,BillingCity,BillingPostalCode,Name,Phone FROM Account WHERE name LIKE :('%' + s + '%') limit 5];
            system.debug('accList '+accList);
        }    
        return accList;
    }
}
2
  • i just cpoy pasted your code, getting following errorautocompletefunctionality: No remoted actions found for 'AutoCompleteDemoController.getAccountList' Error Error: No remoted actions found for 'AutoCompleteDemoController.getAccountList'.
    – Satya
    Commented Nov 4, 2016 at 5:36
  • Have you used @RemoteAction annotation for the method getAccountList in the controller extension?
    – Saroj Bera
    Commented Nov 4, 2016 at 6:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .