7

Question

Is there a native way (meaning without doing js and CSS hacks) to get the required field bar to show up when using inline edit support? Normally when using an inputField I could add required="true" but inline edit support has us use an outputField (although in theory I'd expect this to determine automatically if a field was required or not)

Example

<apex:pageBlock>
  <apex:pageBlockSection columns="1">
    <apex:outputField value="{!account.name}">
      <apex:inlineEditSupport event="ondblclick"/>
    </apex:outputField>
  </apex:pageBlockSection>
</apex:pageBlock>

Screenshot when using Inline Edit Support Screenshot when using Inline Edit Support

Screenshot on standard detail page Screenshot on standard detail page

2
  • I really don't think you can pull this one off without some jQuery. I'd hesitate to call that 'hacking' though. I can provide the code if you want it. Commented Apr 18, 2013 at 12:12
  • That's okay, I'm more concerned with making sure I'm using as much of the standard functionality available before resorting to javascript work arounds. Unfortunately, new visualforce tags seem to always be buggy and none of the issues are EVER documented :( That said, the community would definitely benefit from your answer. Commented Apr 20, 2013 at 16:44

2 Answers 2

4

Not sure about outputField but for selectList and generally custom fileds this is what worked best for me with minimum "hacks"

        <apex:pageBlockSectionItem >  
             <apex:outputLabel value="Month" for="monthList"/>
             <apex:outputPanel styleClass="requiredInput"  layout="block">                 
                <apex:outputPanel styleClass="requiredBlock" layout="block"/>               
                <apex:SelectList size="1" id="monthList"  value="{!month}" >
                   <apex:selectOptions value="{!monthes}" />
                </apex:SelectList>     
             </apex:outputPanel>
        </apex:pageBlockSectionItem>
1
  • Is this considered a bug with the salesforce platform?
    – Mr. Ant
    Commented Jun 11, 2014 at 15:44
2

I found this from http://boards.developerforce.com/t5/General-Development/How-to-find-Required-Fields-For-An-Object/m-p/284873#M55286 that shows how to determine if a field is " Required":

//put all the fields in a map to note which ones are "required"
public map<string,boolean> requiredFieldsMap {get;set;}

Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
Map<String,Schema.SObjectField> M = r.fields.getMap();

requiredFieldsMap=new map<string,boolean>();

for(String fieldName : M.keySet()){ 
    Schema.SObjectField field = M.get(fieldName);
    Schema.DescribeFieldResult F = field.getDescribe();

    //A nillable field can have empty content. 
    //A isNillable Boolean non-nillable field must have a value 
        //for the object to be created or saved. 
    // if F.isNillable() is false then field is mandatory

    requiredFieldsMap.put(fieldName,F.isNillable());
}

Then, in your Visualforce page, you need to be clever in how you represent the displayed fields. You could do something like this:

<apex:outputText style="background-color:red;" rendered="{!NOT(requiredFieldsMap.get('Custom_Field__c'))}">&nbsp;&nbsp;</apex:outputText>

Note: you might get a better effect by changing the CSS style for the above apex:outputText. (Try setting the width:5px; , etc.)

1
  • Yep, definitely a lot of options for determining if it's required. Was more looking for a solution for how to get the native version to show up. I've recreated Salesforce styling plenty of times and then they change things up and the page no longer looks native, hence the desire to see if there was a way to get the apex field tags to behave like they do everywhere else. Commented Jun 7, 2013 at 0:44

You must log in to answer this question.

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