+ Start a Discussion
srutmsrutm 

display a field of sobject in a visual force page on click of a button

i have a field "Assignedto3" in my visual force page like:

 

<apex:outputLabel value="AssignedTo3" for="AssignedTo3"/>
        <apex:inputField id="AssignedTo3" value="{!tsk.Assigned2_To__c}"/>

 

I want it to be displayed ONLY when user clicks on a button "ADD"(to add one more user),in the visual force page,i need  help  in writing the "add" function in my custom controller and changes 2 b made in my vfpage

Best Answer chosen by Admin (Salesforce Developers) 
mast0rmast0r

Try it like this:

 

public Boolean showInput { get; set; }

public YourClassName(){
    // Hide input by default
    showInput = false;
}

public PageReference(){ 
// Here comes your logic
...
// And setting the flag to true
showInput = true;

return null;
}

 

And the visualforce page:

 

 

<apex:commandButton action="{!addWhatYouWant}" value="Add" reRender="myInput"/>

<apex:outputPanel id="myInput">
    <apex:outputLabel value="AssignedTo3" for="AssignedTo3" rendered="{!showInput}"/>
    <apex:inputField id="AssignedTo3" value="{!tsk.Assigned2_To__c}" rendered="{!showInput}"/>
</apex:outputPanel>

 

All Answers

mast0rmast0r

Try it like this:

 

public Boolean showInput { get; set; }

public YourClassName(){
    // Hide input by default
    showInput = false;
}

public PageReference(){ 
// Here comes your logic
...
// And setting the flag to true
showInput = true;

return null;
}

 

And the visualforce page:

 

 

<apex:commandButton action="{!addWhatYouWant}" value="Add" reRender="myInput"/>

<apex:outputPanel id="myInput">
    <apex:outputLabel value="AssignedTo3" for="AssignedTo3" rendered="{!showInput}"/>
    <apex:inputField id="AssignedTo3" value="{!tsk.Assigned2_To__c}" rendered="{!showInput}"/>
</apex:outputPanel>

 

This was selected as the best answer
srutmsrutm

thanks a ton..

 

mast0rmast0r

If it works please mark that as solution, thx.

srutmsrutm

as i said when i click on "Add" button it  displayed  Assignedto3 field,now wen i click add for d next time i want "assignedto4" to be displayed..

i tried rendering "assignedto4" like d same as "assignedto3" but both are being displayed at the same time on the first click  of "add" only..

srutmsrutm

as i said when i click on "Add" button it  displayed  Assignedto3 field,now wat i want is wen i click add for d next time i want "assignedto4" to be displayed..

i tried rendering "assignedto4" like d same as "assignedto3" but both are being displayed at the same time on the first click  of "add" only..

any help would be helpfulll..