+ Start a Discussion
RadnipRadnip 

Is it possible to disable the requirement of fields based on which commandButton is pressed?

 

Is there a quick way to disable a field as required based on what action button is pressed? ie if you have this:

 

<apex:inputCheckbox value="{!confirmTerms}" required="true"/>
<apex:commandButton action="{!confirm}" value="Confirm" id="confirm" />
<apex:commandButton action="{!secondConfirm}" value="secondConfirm" id="secondConfirm" />

 

put something in the required to check for the button eg something like this?:



<apex:inputCheckbox value="{!confirmTerms}" required="{!if($CurrentPage.parameters.action.confirm == true,true,false)}"/>
<apex:commandButton action="{!confirm}" value="Confirm" id="confirm" />
<apex:commandButton action="{!secondConfirm}" value="secondConfirm" id="secondConfirm" />



 

Best Answer chosen by Admin (Salesforce Developers) 
MelliottMelliott

Are you using multiple pages for the routing with the confirm versus second confirm.  If so, you can put the logic by page in your controller.  If page confirm, then required, if page second confirm, not required.  You can use apex messages to throw the errors via the controller. 

All Answers

bob_buzzardbob_buzzard

I don't think you'll be able to use the parameters from the URL in that way, as the form is submitted using a post rather than a get, plus it sounds like you want to check for requiredness at the point that the button is clicked - is that correct?

 

If you are using a custom/extension controller, you could carry out your validation server side.  Otherwise I think you'll have to use javascript to get the behaviour you desire.

Ispita_NavatarIspita_Navatar

Hi,

I think you have to use JavaScript to achieve your objective.

Refer to the code given below:-

<div id=”id1”  style = "display:none;">

<apex:commandButton action="{!secondConfirm}" value="secondConfirm" id="secondConfirm" />
</div>

Now write a JavaScript function on click of button "Confirm" and make the display as block.

Refer to the following code for clarity:-

<script language= "Javascript">

function show()

{

document.getElementById(id1).style.display="block";

}

</script>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

MelliottMelliott

Are you using multiple pages for the routing with the confirm versus second confirm.  If so, you can put the logic by page in your controller.  If page confirm, then required, if page second confirm, not required.  You can use apex messages to throw the errors via the controller. 

This was selected as the best answer
RadnipRadnip

In the end I did it in the controller just thought there might be a neater way to do it without writing everything in the controller as the page reloads anyway on sucessful submission.