You need to sign in to do that
Don't have an account?
LitlleNinja
Apex controller path from javascript
Hi,
I created an home page component made with javascript.
It looks fine except that i don't how to call my controller from my javascript. When i did from javascript from a visualforce page but from full javascript component it looks like the path is different.
I already read this article but it doesn't help( or maybe i just did'nt understand)
Note: when i inspected with firebug i saw this message:
Uncaught ReferenceError: AutoCompleteController is not defined
Here my Controller :
global with sharing class AutoCompleteController { private final Movie__c mov; // Instance fields public String searchTerm {get; set;} public String selectedMovie {get; set;} // Constructor public AutoCompleteController() { } public AutoCompleteController(ApexPages.StandardController stdController) { this.mov= (Movie__c)stdController.getRecord(); } // JS Remoting action called when searching for a movie name @RemoteAction global static List<Movie__c> searchMovie(String searchTerm) { System.debug('Movie Name is: '+searchTerm ); List<Movie__c> movies = Database.query('Select Id, Name,BillingPostalCode__c from Movie__c where BillingPostalCode__c like \'%' + String.escapeSingleQuotes(searchTerm) + '%\''); return movies; } @RemoteAction global static List<Movie__c> searchMovie2(String searchTerm2) { System.debug('Movie Name is: '+searchTerm2); List<Movie__c> movies = Database.query('Select Id, Name,BillingPostalCode__c from Movie__c where BillingPostalCode__c like \'%' + String.escapeSingleQuotes(searchTerm2) + '%\''); return movies; } }
Here my javascript
:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script> <script type="text/javascript" src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css"/> <script type="text/javascript"> /*Create a new variable j$ just to avoid any conflicts with other libraries which may be using $.*/ var j$ = jQuery.noConflict(); /*Capture the list of countries in a Array.*/ var countryArray = ['India', 'USA', 'China','FInland','Norway','Netherlands','England','Ukraine','Russia','Japan','Korea','Burma','Srilanka','Iran','Iceland','Canada','Rome','Australia','Armenia','Albania','Afghanisthan']; /*on Document ready*/ j$(document).ready(function(){ var PLACEHOLDER = 'Enter Movie Name Here'; var movieObjects; var queryTerm; j$('[id$=00Nb00000063dLB]').autocomplete({ minLength: 2, source: function(request, response) { queryTerm = request.term; AutoCompleteController.searchMovie2(request.term, function(result, event){ if(event.type == 'exception') { alert(event.message); } else { movieObjects = result; response(movieObjects); } }); }, focus: function( event, ui ) { j$('[id$=00Nb00000063dLL]').val( ui.item.Name ); j$('[id$=00Nb00000063dLB]').val( ui.item.BillingPostalCode__c ); return false; }, select: function( event, ui ) { j$('[id$=00Nb00000063dLL]').val( ui.item.Name ); return false; }, }) .data( "autocomplete" )._renderItem = function( ul, item ) { var entry = "<a>" + item.Name + " " +item.BillingPostalCode__c; entry = entry + "</a>"; entry = entry.replace(queryTerm, "<b>" + queryTerm + "</b>"); return j$( "<li></li>" ) .data( "item.autocomplete", item ) .append( entry ) .appendTo( ul ); }; /* Add or remove placeholder values*/ j$('[id$=00Nb00000063dLL]').val(PLACEHOLDER); j$('[id$=00Nb00000063dLL]').on("focus", function(event){ j$tgt = j$(event.target); if(j$tgt.val() === PLACEHOLDER ){ j$tgt.val(''); j$tgt.removeClass('placeHolder'); } }); j$('[id$=00Nb00000063dLL]').on( "blur", function(event){ j$tgt = j$(event.target); if(j$tgt.val() === '' ){ j$tgt.val(PLACEHOLDER); j$tgt.addClass('placeHolder'); } }); }); </script>
mynamespace.AutoCompleteController.searchMovie(searchTerm, callback)
My class are not from a managed package because i develop it by myself.
It looks like my classes don't have a namespace.
how can i find it? or as you said wich extension should i use to make it work?
i checked one more time, my controller doesn't have any namespace.
http://img11.hostingpics.net/pics/845371error.jpg
var searchMovieFn = {!$RemoteAction.AutoCompleteController.searchMovie};
You can then call the function using:
searchMovieFn(searchTerm);
If it complains about a missing variable, then you'll know you haven't properly included the controller in the page.
It's looks like doesn't work ='(.
I really don't understand why è_è
I also tried to define the controller with <apex:component> but it's not working :/
hi
the goal of my development change.
i have to make an autocomplete on the shipping zipcode and shipping city.
all the zipcode and city are in a spécial object called "Code_Postal__c"
Here my crontroller :
here my script :
and i still have the problem... when i launched the editing mode my shipping zip code was populate with the value "Enter Code_Postal__c Here" but the search doesnt work.
when i inspected the page with firebug i saw this :
http://img4.hostingpics.net/pics/449322error.jpg
if someone could help me please T_T i'm pretty bad with javascript