Skip to content Skip to sidebar Skip to footer

Define Apex Controller In Javascript Home Component

I have created a custom object Code_Postal__c. The goal is to check into my Code_Postal__c record the city's name with the same ZipCode set by the user on an Account record page. I

Solution 1:

As i said , i found a way to make my auto-complete. It's making a request, and parsing my string. It's not working with parameter..='( I'm trying to find a way to do it dynamically and parse my object (with the item?) Anyway this example is working :

The controller :

global class cpSearch2{ 
    webService static String searchCP() {
        String pickValues='';
        for(Code_Postal__c cp : [Select Commune__c, Code_Postal__c from Code_Postal__c ]){
               pickValues = pickValues +cp.Code_Postal__c+ ' - ' + cp.Commune__c+'+';
        }
        return pickValues;
    }
}

My javascript component:

<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<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="/resources/demos/style.css">
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
<script>var url = document.URL;
if(url.indexOf('001')!=-1)    
{                
    var sid = document.cookie.match(' sid=([^;]*)')[1];   
    sforce.debug.trace=true;
    sforce.connection.sessionId = sid;
    var stages = sforce.apex.execute("cpSearch2", "searchCP", {});
    var staheArray = stages.toString().split("+");
    $ = jQuery.noConflict();
    $(function() {
        var availableTags = staheArray;
        $( "#acc18zip" ).autocomplete({
            source: availableTags
            });
        $( "#acc18zip" ).on("autocompleteselect", function( event, ui ){
            selectedArray = ui.item.value.split(" - ");
            $("#acc18zip").val(selectedArray[0]);
            $("#acc18city").val(selectedArray[1]);
            return false;  
        });
    });
}
</script>

Post a Comment for "Define Apex Controller In Javascript Home Component"