0

I have below code where I want to show the User the available Compliance Incident Names. This is working fine for the first time after page load. Then if I delete the input text field and try re-enter the name, I am not getting the available values. can someone please let me know where I miss it?

I came to know j$(document).ready(function() works only during page load, so during rerender it cant be linked to autocomplete. Can someone please help me? Apex Page

<apex:pageblockSectionItem > 
       <apex:outputText rendered="{!userType == 'Admin' || userType == 'HomeOffice' || userType == 'Field'}">Compliance Incident Name</apex:outputText>
            <apex:inputText styleClass="apexaccountautocomplete" value="{!selectedCI}" >
        <apex:actionSupport event="onchange" action="{!changeEditable}" rerender="pb"/>
     </apex:inputtext> 
    </apex:pageblockSectionItem>

Corresponding Autocomplete Javascript

<script src="https://code.jquery.com/jquery-1.8.2.js"></script>


<script src="https://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>


  <link rel="stylesheet" href="https://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css"/>


 <script type="text/javascript"> var j$ = jQuery.noConflict();
  var apexCIList =[];
  //alert(CIList);
   <apex:repeat value="{!CIList}" var="List">            
      apexCIList.push('{!List.name}');            
  </apex:repeat>
  //on Document ready
  j$(document).ready(function(){
      j$(".apexaccountautocomplete").autocomplete({
          source : apexCIList
   });  
    j$("#button").click(function(){
      alert('somevalue');
     // var obj = document.getElementById("     {!$Component.form.panel.apexaccountautocomplete}");
      alert(obj);
      });   

  });   


</script> 

Apex class code

public list<Compliance_incident_abv__c > getCIList(){
    return [select id,name from Compliance_incident_abv__c limit 25];
}

 public String selectedCI{get;set;}

public void changeEditable(){
    System.debug('selectedCI@@'+selectedCI);
    applyfiler();
   isEditable = isEditable ? false:true;
}

public Boolean isEditable {get; private set;}
  • 1
    you might want to rerender Javascript section. Your code looks bit incomplete. Would be better if you post complete code. – Tushar Sharma Dec 21 '16 at 11:34
  • @TusharSharma I have placed the above javascript code inside the pb page block. Please let me know what I need to post. Shall I post the entire apex page? Will do that if you say. – Testing_SFDC Dec 21 '16 at 11:51
  • 1
    apex:repeat in javascript code is not best practice from consistency and maintainability perspective I think. – Vladyslav K Dec 21 '16 at 15:22
  • @VladyslavKushney Ok. Can you please suggest some thing else – Testing_SFDC Dec 22 '16 at 5:14
0

Thanks I managed to get the root cause. It was due to Javascript document link getting broken due to rerender. So, i had to place below script inside the pageblock and it's just fine for me.

<script>
            if(document.readyState == 'complete')
            {
               j$(".apexaccountautocomplete").autocomplete({
                      source : apexCIList
               });  


            }
            </script>

But I need to create another autocomplete field and that's simply capturing same value as this one. I know it's a different case and needs separate question. Just wanted to keep track of with this one.

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.