[SalesForce] How to make a field editable only if a checkbox is checked

I have a text field that is set to un-editable for all profiles. However if another field (checkbox) is checked, then this text field should become editable and required. I have created a validation rule for the required part. however I need this field remain un-editable when the checkbox is unchecked. Thanks for any input.

Best Answer

You cannot allow them to edit this text field if you make it unallowed by removing access to profiles.

What you can do though, is allow them to edit by profile, but use a VF page in order to display this field. You can then put this VF page on the page Layout for the object. Use the VF page and/or Controller in order to control access to that variable.

<apex:page standardController="Account">
  <apex:inputField value="{!Account.MyTextVal__c}" rendered="{!Account.IsEditable__c}" />
  <apex:outputField value="{!Account.MyTextVal__c}" rendered="{!!Account.IsEditable__c}" />
</apex:page>