2

I have create a field set for a custom object and i am displaying the field set on a VF page. I am not using apex:page block bec i want to change the style of the page so i am displaying using a table. I want to know whether the field is required on not if required then want to display * in the place of default required field indication by the salesforce.

<apex:page id="loginPage" showHeader="false" title="{!$Label.site.site_login}"  standardController="onboarding__c" extensions="onboarding_extCon">

    <style>
        h1{
            font-size:16px;
            padding-left:50px;
            font-family:'trebuchet ms', helvetica, sans-serif;
            color:#3366FF;
            line-height:20px;
        }
        .tableStyle{
            padding-left:50px;
            font-size:14px;
            font-family:'trebuchet ms', helvetica, sans-serif;
            color:#343434;
        }
        .cm_formCss{
             height:100%;
             margin:auto;
             width:960px;
        }
        .tdStyleFirst{
            height:25px;
            margin-bottom:13px;
            margin-left:2px;
            width:50%;
        }
        .tdStyleSecond{
            height:25px;

        }

    </style>


  <apex:composition template="{!$Site.Template}">
    <apex:define name="body">  
       <apex:form styleClass="cm_formCss" id="cmForm" >

              <h1>Onboarding</h1>
              <table class="tableStyle">              
              <apex:repeat value="{!$ObjectType.onboarding__c.FieldSets.Onboarding_Field_set}" var="f"> 

                    <tr>
                        <td class="tdStyleFirst"><apex:outputText value="{!f.Label}" />  </td>                       
                        <td><apex:inputField value="{!onboarding__c[f]}" />  </td>
                    </tr>        

              </apex:repeat>
                      <tr>
                          <td></td>
                      </tr> 
                      <tr>
                          <td></td>                          
                          <td> <apex:commandButton action="{!Save}" value="Submit"/>
                               <apex:commandButton action="{!cancel}" value="Reset"/> </td>
                      </tr>
              </table>


      </apex:form>
    </apex:define>
  </apex:composition>
</apex:page>

Please guide me if anybody have any idea.

5

You need to use getRequired() method of the FieldSetMember:

{!IF(f.Required, '*', '')}

So in your case it wiil look like this:

<tr>
    <td class="tdStyleFirst"><apex:outputText value="{!f.Label}" /></td>                       
    <td>
        <apex:outputText value="*" style="color:red;" rendered="{!f.Required}"/>
        <apex:inputField value="{!onboarding__c[f]}" />
    </td>
</tr>   
| improve this answer | |
  • thanks but this only works for if we set required in field set. So i have added 1 more line of code to get the field required from db also. rendered="{!OR(f.DBRequired, f.required)}". But now the issue it shows required on f page for both Datebase and field set but it works only for DBRequired (Display error message only if the field is required in db). – AnuRaj Jan 17 '14 at 4:48
  • 1
    thnaks i solved it. By adding required="{!OR(f.DBRequired, f.required)}" to inputfield. – AnuRaj Jan 17 '14 at 4:50
2

I have solved this issue. If the field is required on DB or it is made required on field set for both it is working and it is displaying the error message i the same manner. My code :


          <h1>Onboarding</h1>
          <table class="tableStyle">              
          <apex:repeat value="{!$ObjectType.onboarding__c.FieldSets.Onboarding_Field_set}" var="f"> 

                <tr>
                    <td class="tdStyleFirst">
                        <apex:outputText value="{!f.Label}"  /> 
                        // Change made here on rendered 
                        <apex:outputText value="*" style="color:red;" rendered="{!OR(f.DBRequired, f.required)}" /></td> 
                        // Change made here on required                       
                    <td><apex:inputField value="{!onboarding__c[f]}" required="{!OR(f.DBRequired, f.required)}" />  </td>
                </tr>        

          </apex:repeat>
                  <tr>
                      <td></td>
                  </tr> 
                  <tr>
                      <td></td>                          
                      <td> <apex:commandButton action="{!Save}" value="Submit"/>
                           <apex:commandButton action="{!cancel}" value="Reset"/> </td>
                  </tr>
          </table>


  </apex:form>
</apex:define>

| improve this answer | |

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.