function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PegazysPegazys 

apex:InputField switching values for Required Attribute

The required attribute for apex:InputField is set to true or false.

 

I want it to be set to true or false based on the value entered for another field

 

Can this be controlled using Javascript or thru the Controller Method?

 

 

bob_buzzardbob_buzzard

You can certainly do this through the controller, but you would have to submit the changes made to the "controlling" field and then re-render the input field to update whether it is required or not.    You wouldn't simply be able to make this required via javascript, as this is dictated by the styling for the field.

rohitsfdcrohitsfdc

hi,

you can do that by calling a controller function for required attribute, like

<Apex:inputField value="{!contact.account.accountnumber}" required="{!req}" />

 

Controller:

public boolean getReq(){
    //write your logic here

// if okay, return true, else return false
    }