1

I am trying to make the apex:inputField of the records that meets a certain criteria readOnly when the condition is met.

    <script>
        function isTooLate(status) {
            console.log('yo');
            const validStatus = ['New Request', 'Technical Validation', 'Waiting for Customer Approval'];
            return validStatus.includes(status);
        }
    </script>

    <apex:pageBlockTable value="{!wrappers[fieldSetKey]}" var="wrapper" id="table" style="color:blue">
        <apex:inputField value="{!wrapper.product[field]}" html-disabled="{isTooLate('{!wrapper.product.Status}')}" >
    </apex:pageBlockTable>

this doesn't work, the function is not called and all the rows are disabled

Is there a way to dynamically change the apex:inputField for a apex:outputField or achieve what I want?

1 Answer 1

0

I think you will have to use an apex:inputField and an apex:outputField as a combo to disable / enable your data. Like this:

<apex:pageBlockTable value="{!wrappers[fieldSetKey]}" var="wrapper" id="table" style="color:blue">
    <apex:outputField value="{!wrapper.product[field]}" 
                      rendered={! wrapper.product.Status = 'New Request' || 
                                  wrapper.product.Status = 'Technical Validation' ||
                                  wrapper.product.Status = 'Waiting for Customer Approval' } >
    <apex:inputField value="{!wrapper.product[field]}" 
                      rendered={! NOT(
                                  wrapper.product.Status = 'New Request' || 
                                  wrapper.product.Status = 'Technical Validation' ||
                                  wrapper.product.Status = 'Waiting for Customer Approval'
                                  )} >
</apex:pageBlockTable>

The reason I've done it this way is because there are no events you can use to harness to enable/disable this data as it is rendered.

You COULD do this in the wrapper - just set a rendered boolean in a loop in the controller.

There are other issues with your visualforce syntax too, but since I think that approach isn't going to work, I won't try to fix them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .