function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RitikRitik 

Jquery not invoking

Hi,

I have a code wherein we have used JQuery to for autocomplete (jQuery.ui.autocomplete.prototype._renderItem).

Here problem is that if first "MyFirstFieldAutocomplete" gets invokes then third "MyThirdFieldAutocomplete" doesn't gets invoked.
While auto populate functionality works fine if value in MyThirdFieldAutocomplete is filled first.
(One more problem is that even no console logs/alerts gets generated(so that I can debug) if we fill MyFirstFieldAutocomplete first.)


**************CODE******************************

 jQuery(document).ready(function(){
    jQuery.ui.autocomplete.prototype._renderItem = function( ul, item) {
          var re = new RegExp(this.term, "i") ;
          var t = item.label.replace(re,"<span style='font-weight:bold;color:Blue;'>" + this.term + "</span>");
          return jQuery( "<li></li>" )
              .data( "item.autocomplete", item )
              .append( "<a style='cursor: pointer; background-color:white;'>" + t + "</a>" )
              .appendTo( ul );
    };
    
    jQuery('.MyFirstFieldAutocomplete, .MySecondFieldAutocomplete, .MyThirdFieldAutocomplete, ').each(function(){
        var thisInput = this;
        
        console.log('this' + this);
        jQuery(this).autocomplete({
            minLength: 2,            
            source: function(request, response) {  
                queryTerm = request.term;
                console.log('queryTerm ' + queryTerm );
                
                var filterValue = '';
                var searchObject = '';
                var fieldList = '';
                var filterField = '';
                
                if(jQuery(thisInput).hasClass('MyFirstFieldAutocomplete')){
                    filterValue = 'First RecordType';
                    searchObject = 'Account';
                    fieldList = 'BillingCountry';
                    filterField = 'recordtype.name';
                }else{
                    if(jQuery(thisInput).hasClass('MySecondFieldAutocomplete')){
                        filterValue = 'SecondFilter';
                    }
                    searchObject = 'CustomObject__c';
                    filterField = 'customField__c';                
                }
                
                if(jQuery(thisInput).hasClass('MyThirdFieldAutocomplete')){
                    filterValue = 'Third RecordType';
                    searchObject = 'Account';
                    fieldList = 'BillingCountry';
                    filterField = 'recordtype.name';
                    alert('High School');
                    console.log(filterValue, searchObject, fieldList, filterField);
                    console.log('Test2');
                    console.log('queryTerm inside MyThirdField' + queryTerm );
                }
                
                console.log(filterValue, searchObject, fieldList, filterField);
                
                myClassController.getAutoCompleteList(filterValue, request.term, searchObject, fieldList, filterField, 
                    function(result, event){
                    if(event.type == 'exception'){
                        alert(event.message);
                    }else{
                        sObjects = result;
                        response(sObjects);
                    }
                });
            },
            select: function(value, data){
                if (typeof data == "undefined") {
                    this.value= value;
                }else{
                    lookupPick2('formId',this.id+'_lkid',this.id,data.item.recordId,htmlDecode(data.item.name),false);
                }
                return false;
            }
        });             
    });
});


<td>
   <apex:inputField value="{!lstCustomObjNew.customFieldLookup__c}" id="thirdId" styleClass="MyThirdFieldAutocomplete"/>
</td>


Any help would be appriciated.


Regards,
Ritik
Shashikant SharmaShashikant Sharma
Check if you are not getting any Java Script Error. If you are getting then let me know what is the error.
RitikRitik
With F12, in chrome, nothing is coming for third autocomplete when first one is invoked first .


note:- I have used @RemoteAction to invoke Sosl for autocomplete.......