Friday, March 15, 2013

Disable and Enable inputtext, copy Date and Text


1.Enabling and Disabling inputtext box through inputcheckbok

<apex:page controller="checkingcls" id="p">
     <apex:form id="f">
         <apex:actionFunction name="endis" action="{!checkmeth}"/>
             <apex:inputCheckbox onchange="endis()" id="icb" value="{!val}"/>
                    <apex:outputPanel >
                       <apex:inputtext disabled="{!tryonce}" id="it"/>
                    </apex:outputPanel>
        </apex:form>
</apex:page>

Apex Class:

public with sharing class checkingcls {
    public boolean val { get; set; }
    public PageReference checkmeth() {
        if(val==true)
            tryonce=false;
        if(val==false)
            tryonce=true;
        return null;
    }
    public boolean tryonce { get; set; }
        public checkingcls(){
            tryonce=true;
                             }    
}

2.dynamic copy of text from one inputtext to another inputtext

<apex:page id="p">
<script>
    function copycode(){
        var texts=document.getElementById('p:f:pb:it1').value;
        //alert(texts);
        var texts1=texts;
        //alert(texts1);
        document.getElementById('p:f:pb:it2').value=texts1;
                       }
</script>
  <apex:form id="f" >
      <apex:pageblock id="pb" >
          <apex:inputtext id="it1" onkeyup="copycode()" title="one"/><br/>
          <apex:inputtext id="it2" size="30"/><br/> 
      </apex:pageblock>
  </apex:form>
</apex:page>

3.copying date from inputfield to inputtext

<apex:page standardController="Account" id="p" >
<script>
    function copdate(){
       // alert('Hi');
        var cop=document.getElementById('p:f:pb:if').value;
        //alert(cop);
        document.getElementById('p:f:pb:it').value=cop;
                      }
</script>

    <apex:form id="f">   
        <apex:pageBlock id="pb">
            <apex:inputField value="{!Account.week__c}" id="if" onchange="copdate()" /><br/>
            <apex:inputtext id="it" />
        </apex:pageBlock>
    </apex:form>
</apex:page>

---------------------------------------------------------------------------------------------------
The above three tasks implemented in one VF page and Apex Class
---------------------------------------------------------------------------------------------------

Visualforce Page:


<apex:page standardcontroller="Account" extensions="checkingcls" id="p">
<script>
    function copdate(){
       // alert('Hi');
        var cop=document.getElementById('p:f:pb:pbs1:if').value;
        //alert(cop);
        document.getElementById('p:f:pb:pbs1:pbsi1:it').value=cop;
                      }
</script>
     <apex:form id="f">
     <apex:pageblock id="pb" >
     <apex:actionFunction name="endis" action="{!checkmeth}"/>
     <apex:pageblocksection title="EnDis" id="pbs">
         <apex:pageblocksectionitem id="pbsi">
             <apex:inputCheckbox onchange="endis()" id="icb" value="{!val}"/>
             <apex:inputtext disabled="{!tryonce}" id="it" value="{!var}"/>   
         </apex:pageblocksectionitem>                 
     </apex:pageblocksection>
     <apex:pageblocksection title="Date" id="pbs1">
         <apex:inputField value="{!Account.SLAExpirationDate__c}" id="if" onchange="copdate()"/><br/>
         <apex:actionFunction name="twodisab" action="{!disabmeth}"/>
             <apex:inputCheckbox id="icb" onchange="twodisab()" value="{!sval1}" />
         <apex:pageblockSectionItem id="pbsi1">
             <apex:inputtext id="it" disabled="{!itdisab}"/>
        
         <apex:selectList value="{!selected}" size="1" id="sl" disabled="{!sldisab}">
             <apex:selectOptions value="{!items}"/>
         </apex:selectList>
          </apex:pageblockSectionItem>
     </apex:pageblocksection>
     </apex:pageblock>
     </apex:form>
</apex:page>

Apex Class:

public with sharing class checkingcls {
        public boolean itdisab{get; set;}
        public boolean sldisab{get; set;}
        public boolean sval1{get; set;}
        public string selected{get; set;}
        public List<selectoption> items{get; set;}
    public checkingcls(ApexPages.StandardController controller) {
            sval1=true;                
            tryonce=true;
            var='Narayana Reddy';
            items=new List<selectoption>();
            items.add(new selectoption('1','08.00AM'));
            items.add(new selectoption('2','09.00AM'));
            items.add(new selectoption('3','10.00AM'));
            items.add(new selectoption('4','11.00AM'));
            items.add(new selectoption('5','12.00PM'));
            items.add(new selectoption('6','01.00PM'));
            items.add(new selectoption('7','02.00PM'));
            items.add(new selectoption('8','03.00PM'));
            items.add(new selectoption('9','04.00PM'));
            items.add(new selectoption('10','05.00PM'));
            items.add(new selectoption('11','06.00PM'));
            items.add(new selectoption('12','07.00PM'));
            items.add(new selectoption('13','08.00PM'));         
    }

    public String var { get; set; }
    public boolean val { get; set; }
    public PageReference checkmeth() {
        if(val==true)
            tryonce=false;
        if(val==false)
            tryonce=true;
        return null;
    }
    public boolean tryonce { get; set; }
    
    public PageReference disabmeth(){
            if(sval1==false)
            {
                itdisab=true;
                sldisab=true;
            }
            if(sval1==true)
            {
                itdisab=false;
                sldisab=false;
            }
        return null;
                                    }      
            }

No comments:

Post a Comment