0

I have this fieldset on my page which uses SLDS design:

<apex:pageBlockSection columns="2" id="ppCard">
<apex:repeat value="{!$ObjectType.my_Object__c.FieldSets.myFieldset}" var="ap1">
    <apex:inputField value="{!ps[ap1.fieldPath]}" 
         styleClass="{! IF((ap1.fieldPath == 'field1'), 'fieldValue1', '')} 
                     {! IF((ap1.fieldPath == 'field2'), 'fieldValue2', '')} inputfield"
         label="{! IF((ap1.fieldPath == 'field1'), ap1.label+' (without Salutation)', ap1.label)}" 
         required="{!OR(ap1.required, ap1.dbrequired)}"/>
</apex:repeat>

If a field is required on fieldset definition, I would like its inputfield to be red also on page load. How can I get the specific field to be able to change its required attribute? For now, I am just making all inputfields required on page but not on the field set definition. I want to make it required only if it is also required on fieldset. Is there any way on how to do it?

For example: if field2 is the only field required on fieldset, I want to remove also the required attribute of field1 on page. Like using $('.samplestyleclass').val('').removeAttr('required') on JS for example... Is it possible?

1

I think following logic might work for you. Display fields based on rendered condition as follows:

<apex:repeat value="{!$ObjectType.my_Object__c.FieldSets.myFieldset}" var="ap1">

    <!-- This is non mandatory block -->
    <apex:inputField value="{!ps[ap1.fieldPath]}" 
             label="{! IF((ap1.fieldPath == 'field1'), ap1.label+' (without Salutation)', ap1.label)}" 
             rendered="{!NOT(AND(ap1.required, ap1.dbrequired))}"/>

     <!-- This is mandatory block -->
     <apex:outputPanel layout="block" styleClass="requiredInput" rendered="{!OR(ap1.required, ap1.dbrequired)}">
        <apex:outputPanel layout="block" styleClass="requiredBlock"/>
            <apex:inputField value="{!ps[ap1.fieldPath]}" 
         label="{! IF((ap1.fieldPath == 'field1'), ap1.label+' (without Salutation)', ap1.label)}" 
         required="true" />
     </apex:outputPanel>
</apex:repeat>

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.