2016-10-07 5 views
0

Mein Controller:Aktivieren und Deaktivieren der Schaltfläche durch die Kontrollkästchen in jquery?

public class AccountEditController { 

    public String closePopup { get; set; } 

    accountwrapper1 makeEdit; 
    List<accountwrapper1> listAccount = new List<accountwrapper1>(); 
    List<Account> selectableAccount = new List<Account>(); 
    //set<Account> selectableAccount2 = new set<Account>(); 
    //public Boolean showPanel {get; set;} 
    public Boolean showPopup { get; set; } 

    public AccountEditController() { 
      showPopup = False; 
     //showPanel = False; 
    } 

    public List<accountwrapper1> getAccounts() { 
     if(listAccount == Null){ 
      for(Account a: [SELECT Id, Name, BillingCountry, Phone FROM Account]) 
      listAccount.add(new accountwrapper1(a)); 
      return listAccount; } 
     else{ 
      listAccount.clear(); 
      for(Account a: [SELECT Id, Name, BillingCountry, Phone FROM Account]) 
      listAccount.add(new accountwrapper1(a)); 
      return listAccount;    
      }   
    } 

    public PageReference showToPopup() { 
    // public PageReference showToPanel() { 
     showPopUp = True; 
     return Null; 
     //showPanel = True; 
     } 

    public PageReference getSelectable() { 
     system.debug('Hello'); 
     selectableAccount.clear(); 
     for(accountwrapper1 accwrapper : listAccount) 
     if(accwrapper.selected == True) 
     selectableAccount.add(accwrapper.acc); 
     system.debug(selectableAccount); 
     return Null;    
    } 

    public string BillingCountry { 
     get; 
     set; 
    } 


    /*public PageReference Savemeth() { 
     for(account acc :selectableAccount) { 
       acc.BillingCountry = BillingCountry; 
       selectableAccount2.add(acc); 

     }  
    update selectableAccount2; 
    showPopup = False; 
    return Null; 

    }*/ 

    public PageReference Savemeth() 
    { 
     map<Id, Account> mapAccountForUpdate = new map<Id, Account>(); 
     for(account acc :selectableAccount) 
     { 
      system.debug('BillingCountry: '+BillingCountry); 
      acc.BillingCountry = BillingCountry; 
      mapAccountForUpdate.put(acc.Id, acc); 
     }  
     update mapAccountForUpdate.values(); 
     selectableAccount = new List<Account>(); 
     showPopup = Null; 
     BillingCountry = ''; 
     //showPopup = False; 
     return null; 
    } 

    public PageReference cancelmeth() {   
     return Null; 
    } 

    public PageReference closePopup() { 
     showPopup = Null; 
     BillingCountry = ''; 
     //showPopup = False; 
     return Null; 
    } 

    public PageReference GetSelectedAccounts() 
    { 
     if(selectableAccount.size()>0) { 
     system.debug(selectableAccount.size()); 
     system.debug(selectableAccount); 
     showPopup = Null; 
     return Null; 
     } 
     else 
     showPopup = Null; 
     return Null; 
    } 


    public class accountwrapper1 
    {    
     public Account acc{get; set;}  
     public Boolean selected {get; set;} 
     public accountwrapper1(Account a) 
     { 
      acc = a; 
      selected = False; 
     } 
    } 
} 

Hier ist der Code für die die Liste des Kontos auf die Aktualisierung Weise im Bereich des Rechnungslandes der account.by die Auswahl des Kontrollkästchen Wert der Bereitstellung ist " Richtig ", dass das entsprechende Konto aktualisiert werden soll. Hier muss der aktualisierte Wert durch die Eingabe des Modell-Popup-Felds im Feld" Rechnungsland "geändert werden.

Meine Seite:

<apex:page controller="AccountEditController" applyHtmlTag="true"> 
<head> 
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /> 
</head> 
<script> 
    $(document).ready(function(){  
     select();   
    }); 

    function select(){ 
     $('[id*=chkb1]').change(function(){ 

      $("[id*='chkb2']").attr("checked",this.checked); 
      getSelectable(); 

     }); 

     $('[id*=chkb2]').click(function(){ 

      if($('[id*=chkb2]').length== $("[id*='chkb2']: checked").length) 
      {   
       $("[id*='chkb1']").attr("checked",this.checked); 
       getSelectable();  

      } 
      else 
      {  
       var checkboxes = document.getElementsByTagName('input'); 
       var counter = 0; 
       var counter1 = 1; 

       for (var i = 0; i < checkboxes.length; i++) { 
        if (checkboxes[i].type == 'checkbox') { 
         counter++; 
         if(checkboxes[i].checked == true){ 
          counter1++; 
         } 
        } 
       }   
       if(counter==counter1){ 
        $("[id*='chkb1']").attr("checked",this.checked); 
        getSelectable(); 
       } else { 
         $("[id*='chkb1']").removeAttr("checked"); 
         getSelectable(); 
        }     
      }   
     }); 
    } 

</script> 
    <style type="text/css"> 
    .PopupBackground{ 
     background-color: white; 
     opacity: 0.8; 
     filter: alpha(opacity = 20); 
     position: absolute; 
     width: 100%; 
     height: 200%; 
     top: -100px; 
     left: 10px; 
     z-index: 9998; 
    } 
    .AccountEdit{ 
     background-color: white; 
     border-width: 8px; 
     border-style: solid; 
     z-index: 9999; 
     left: 30%; 
     padding:10px; 
     position: absolute; 
     width: 350px; 
     margin-left: 75px; 
     top:300px; 
    } 
    </style> 
     <apex:form > 
      <apex:actionFunction name="getSelectable" action="{!getSelectable}" reRender="Output"/> 
      <apex:pageBlock Title="List of Accounts" > 

        <apex:pageBlockButtons location="top"> 
         <apex:commandButton value="Get selected Records" action="{!showToPopup}" rerender="Output" id="button"/> 
         <apex:commandButton value="Cancel" action="{!closePopup}" rendered="output"/> 
         <!-- <apex:commandButton value="Get selected Records" action="{!showToPanel}" rerender="Output" id="button"/>----> 

        </apex:pageBlockButtons> 

       <!-- {!showPanel}----> 
         <apex:outputPanel id="Output"> 
          <apex:outputPanel styleClass="PopupBackground" layout="black" rendered="{!showPopup}"> 
           <apex:outputPanel styleClass="AccountEdit" layout="black" rendered="{!showPopup}"> 
         <!--- <apex:outputPanel rendered="{!showPanel}">-----> 
          <!---{!showPanel}----------> 
           <apex:outputLabel value="BillingCountry: "></apex:outputLabel> 
           <apex:inputText id="BillingCountry" value="{!BillingCountry}" size="40" style="height:13px;font-size:11px;"/><br />     
           <center><apex:commandButton value="Save" action="{!Savemeth}" reRender="Initialtable,Output" oncomplete="select();"/> 
           <!-- <apex:commandButton value="cancel" action="{!cancelmeth}"/>----> 
           <apex:commandButton value="Cancel" action="{!closePopup}"/></center> 
           </apex:outputPanel> 
          </apex:outputPanel>     
         </apex:outputPanel> 
       <!-- <apex:commandButton value="cancelPopup" action="{!closePopup}"/>---> 
        <apex:pageBlockSection Title="List of Available Accounts" columns="1" collapsible="true"> 
          <apex:pageblockTable value="{!accounts}" var="a" id="Initialtable"> 

           <apex:column > 
            <apex:facet name="header"> 
             <apex:inputCheckbox value="{!a.selected}" id="chkb1"> 
              <!-- <apex:actionSupport event="onclick" action="{!getSelectable}" reRender="Output"/> --> 
             </apex:inputCheckbox> 
            </apex:facet> 
            <apex:inputCheckbox value="{!a.selected}" id="chkb2" /> 
            <!-- <apex:actionSupport event="onclick" action="{!getSelectable}" reRender="Output"/> --> 
           </apex:column> 

           <apex:column headervalue="Account Name" value="{!a.acc.Name}" width="200"/> 
           <apex:column headervalue="Phone" value="{!a.acc.Phone}" width="300"/> 
           <apex:column headervalue="Billing Country" value="{!a.acc.BillingCountry}" width="300"/> 

          </apex:pageblocktable> 
        </apex:pageBlockSection> 

      </apex:pageblock> 
     </apex:form> 
</apex:page> 

Also hier die meine Seite, die ich die „Get ausgewählte Datensätze“ Button ist es in hier will so sollte Es ist sein in dem Zustand des atleast eines Kontrollkästchen wird aktiviert sein ausgewählt in. Und es sollte auch deaktivieren in dem Zustand der es gibt kein Kontrollkästchen sind in Auswahlmodus. (Hinweis: Bitte sagen Sie den Ablauf der Ausführung in der jQuery wie geschrieben, es ist hilfreich, klar in meiner Sicht zu verstehen) Also bitte helfen Sie mir, diese Funktion für Antworten im Voraus zu tun.

+0

Wow das ist eine Menge Code! – deeveeABC

+0

In der Tat, kann ich auch vorschlagen, die Op, erstellen Sie einen kleinen reproduzierbaren Testfall von dem, was Sie nach. Stack Overflow-Snippets wären ideal! Ihre Frage war sehr spezifisch, aber Ihr Beispiel nicht. Ihre Frage ist auch jQuery-spezifisch. Ihr Beispiel benötigt also nicht den gesamten Visualforce-Code. Dadurch haben Sie eine viel bessere Chance auf eine Antwort. – Keith

Antwort

0

Wenn ich Ihren Zweck verstehe, können Sie eine Variable zum Zählen Kontrollkästchen aktiviert sind.

$(document).ready(function() { 
 
    $('.btn').prop('disabled', true); 
 

 
}); 
 
var chbchecked = 0; 
 
$('.chb').change(function() { 
 
    if (this.checked) { 
 
    chbchecked++; 
 
    $('.btn').prop('disabled', false); 
 
    } else { 
 
    chbchecked--; 
 
    if (chbchecked == 0) { 
 
     $('.btn').prop('disabled', true); 
 
    } 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<input type="checkbox" class="chb" value="1" /><a>chb1</a> 
 
<input type="checkbox" class="chb" value="2" /><a>chb2</a> 
 
<input type="checkbox" class="chb" value="3" /><a>chb3</a> 
 
<button type="submit" class="btn"> 
 
    Save 
 
</button>

+0

Vielen Dank barzin !!! du gibst mir eine Idee ... – MohanRaj

Verwandte Themen