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.
2 Answers
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>
-
I just realized that this won't show up in the 'EDIT' view of a layout. It would have some issues as well that needs worked around unless you added a button here that would allow it to save in the view section.– dphilCommented Oct 20, 2014 at 18:54
You will want to make the field editable by all profiles that will need to edit it. Then you could use a similar validation rule to make sure that the text field remains null if the checkbox equals 0. I would try the following:
AND(Checkbox__c = 0, (NOT(ISNULL(Text_Field__c)))
Per metadaddy's comment, you could combined this with the other answer to dynamically show/hide the field. You could always consider using record types with page layouts that make the field visible & required, and create a workflow rule that updates the Record Type field to switch when the checkbox gets checked.
-
Combine this answer with dphil's and you pretty much have the whole thing. Commented Oct 20, 2014 at 18:40
-
The main issue I would have with this is that the validation rule would break if the box was checked and the text field was given a value. You could no longer uncheck that box if needed. If you could find a way around that it would be close to what they are asking for.– dphilCommented Oct 20, 2014 at 18:53
-
1Unless the intention is that data is removed from that field if the checkbox is ever unchecked. You could add in a workflow rule that would null the text field if the checkbox was ever unchecked. Commented Oct 20, 2014 at 18:56