0

I have outputfield to show the value of the field in Edit Visualforce page. I want to make this outputfield editable when checkbox field is checked

<apex:pageblocksection>    
      <apex:outputText value={!Object__c.ExampleField__c}>
</apex:pageblocksection>

Now am adding one checkbox field and when this checkbox is checked, the outputtext field should become editable.

    <apex:pageblocksection>
          <apex:inputText value="{!Object__c.CheckboxField__c}"
    </apex:pageblocksection>

//Make the below field editable when above checkbox is checked

    <apex:pageblocksection>    
          <apex:outputText value="{!Object__c.ExampleField__c}">
    </apex:pageblocksection>

I have tried with having inputtext and rendered="{!IF(Object__c.CheckboxField__c == true, true, false)}". But it is not working as expected.

Thanks!!

2

I would use apex:inputCheckbox (instead of inputText) with action support, rerender the block containing input and output fields rendered conditionally.

Following is psuedo code:

<apex:pageblocksection>
    <apex:inputText value="{!Object__c.CheckboxField__c}">
        <apex:actionSupport event="onchange" 
            rerender="editableBlock" />
    </apex:inputText>
</apex:pageblocksection>

<!-- below field editable when above checkbox is checked -->
<apex:pageblocksection id="editableBlock">    
    <apex:outputText value="{!Object__c.ExampleField__c}" 
        rendered="{!NOT(Object__c.CheckboxField__c)}">
    <apex:inputText value="{!Object__c.ExampleField__c}" 
        rendered="{!Object__c.CheckboxField__c}">
</apex:pageblocksection>
  • Thanks for your answer. I'll mark this as answer. Once I did like this the formatting is collapsed. Can we do anything to bring back the default formatting?. – Prince Feb 7 '17 at 9:47
  • I am not sure what you mean by formatting, unable to visualize! – Raul Feb 7 '17 at 9:52
  • I have pageblocksection inside another pageblocksection so the default style formatting of the Examplefield__c is collapsing. Is there any workaround for this to bring back the default stying?. – Prince Feb 7 '17 at 12:55
  • A pageblock section should never be inside another one, maybe render them conditionally – Raul Feb 7 '17 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.