You need to sign in to do that
Don't have an account?

i have a form with save button and view records buttons. Now, while clicking on view records button the required fields should avoid.
Here is my code.
VFPage:-
<apex:page Standardcontroller="Doctor__c" extensions="DoctorView" >
<apex:form >
<apex:pageMessages />
<apex:tabPanel switchType="Client" >
<apex:tab label="Doctor" >
<apex:pageBlock >
<apex:pageBlockSection columns="2">
<apex:inputField value="{!Doctor__c.Name__c}"/>
<apex:inputField value="{!Doctor__c.DOB__c}"/>
<apex:inputField value="{!Doctor__c.ContactNumber__c}"/>
<apex:inputField value="{!Doctor__c.Department__c}"/>
</apex:pageBlockSection>
<apex:pageblockbuttons location="bottom">
<apex:commandButton value="Save" action="{!doctorRecord}" />
</apex:pageblockbuttons>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="ViewDetails" action="{!viewRecords}" />
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!doctorList}" var="dL">
<apex:column headerValue="Name" value="{!dL.Name__c}"/>
<apex:column headerValue="Phone" value="{!dL.ContactNumber__c}"/>
<apex:column headerValue="DOB" value="{!dL.DOB__c}"/>
<apex:column headerValue="Department" value="{!dL.Department__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:tab>
</apex:tabPanel>
</apex:form>
</apex:page>
Apexclass:-
public class DoctorView {
public Doctor__c doctor = new Doctor__c();
public List<Doctor__c> doctorList{get;set;}
public DoctorView(ApexPages.StandardController controller) {
this.doctor = (Doctor__c)controller.getRecord();
}
public pageReference doctorRecord()
{
insert doctor;
return null;
}
public pageReference viewRecords()
{
doctorList = new List<Doctor__c>();
doctorList = [Select Id,Name__c,ContactNumber__c,DOB__c,Department__c from Doctor__c];
return null;
}
}
VFPage:-
<apex:page Standardcontroller="Doctor__c" extensions="DoctorView" >
<apex:form >
<apex:pageMessages />
<apex:tabPanel switchType="Client" >
<apex:tab label="Doctor" >
<apex:pageBlock >
<apex:pageBlockSection columns="2">
<apex:inputField value="{!Doctor__c.Name__c}"/>
<apex:inputField value="{!Doctor__c.DOB__c}"/>
<apex:inputField value="{!Doctor__c.ContactNumber__c}"/>
<apex:inputField value="{!Doctor__c.Department__c}"/>
</apex:pageBlockSection>
<apex:pageblockbuttons location="bottom">
<apex:commandButton value="Save" action="{!doctorRecord}" />
</apex:pageblockbuttons>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="ViewDetails" action="{!viewRecords}" />
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!doctorList}" var="dL">
<apex:column headerValue="Name" value="{!dL.Name__c}"/>
<apex:column headerValue="Phone" value="{!dL.ContactNumber__c}"/>
<apex:column headerValue="DOB" value="{!dL.DOB__c}"/>
<apex:column headerValue="Department" value="{!dL.Department__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:tab>
</apex:tabPanel>
</apex:form>
</apex:page>
Apexclass:-
public class DoctorView {
public Doctor__c doctor = new Doctor__c();
public List<Doctor__c> doctorList{get;set;}
public DoctorView(ApexPages.StandardController controller) {
this.doctor = (Doctor__c)controller.getRecord();
}
public pageReference doctorRecord()
{
insert doctor;
return null;
}
public pageReference viewRecords()
{
doctorList = new List<Doctor__c>();
doctorList = [Select Id,Name__c,ContactNumber__c,DOB__c,Department__c from Doctor__c];
return null;
}
}
Use: Immediate="true" in your command button.
<apex:commandButton immediate="true" value="ViewDetails" action="{!viewRecords}" />
Or you could use onclick event of button and call a java scrpt method to naigate.
All Answers
Use: Immediate="true" in your command button.
<apex:commandButton immediate="true" value="ViewDetails" action="{!viewRecords}" />
Or you could use onclick event of button and call a java scrpt method to naigate.