3

Well this initially seemed very simple but came out to be a disaster. If you are using a inputfield this is pretty easy just use the required="true" attribute and you are good go.

But I was a bit surprised there are no option to mark a PICKLIST field required when using inlineEditSupport basically there is no required attribute for the outfield tag which we generally use for inlineEdit. I did a lot of research on this topic but couldnt find a solution.

<apex:outputField value="{!MyObject__c.MyPicklist__c}" >
       <apex:inlineEditSupport event="ondblclick"/>
</apex:outputField>

I know there are workarounds like

  1. Using a validation rule to throw an error and handle the same in apex to show a pagemessage
  2. Or simply use apex to show pageMessage
  3. Use jQuery/JS

I am just wondering if there any other way ? something like marking required in VF

5
  • Not the answer you are looking for, but I think you have listed the possible workarounds. It can be done in various ways using jQuery, Apex, or Validation. As far as I can see, there is no simpler way, such as setting an attribute in the VF tag. Oct 23, 2013 at 1:03
  • Did you try making fields required in Object Level instead of VF required='true' method?
    – Jag
    Oct 23, 2013 at 2:29
  • @Jag I am talking about Picklist field. You cannot make a picklist field required from field level
    – Avidev9
    Oct 23, 2013 at 8:38
  • @Dunc44 even jquery will be a bit of pain here. The only way out seems to be Apex or Validation. but that will overkill for such a task. I think I can call it a missing feature :P
    – Avidev9
    Oct 23, 2013 at 8:40
  • @avidev9, I agree. Didn't say any of those ways were simple. Oct 23, 2013 at 12:00

1 Answer 1

4

You could do the formatting in VF-only, but it will also show while not in edit-mode:

 <apex:outputLabel value="picklistLabel"/>
 <apex:outputPanel layout="block" styleClass="requiredInput">
     <apex:outputpanel layout="block" styleClass="requiredBlock"/> 
     <apex:outputField value="{!MyObject__c.MyPicklist__c}" >
        <apex:inlineEditSupport event="ondblclick"/>
     </apex:outputField>
</apex:outputPanel>

Note that you should still do the Validation with a validation rule, as this is merely a layout change.

2
  • As mentioned, while this gives the appearance of being required, it has the same issue as the original question. Still need some additional work to ensure it is populated. Oct 23, 2013 at 13:42
  • @Dunc44 I think there should be a parameter for outfield or may be for the inlineEdit support to mark the field required. I am aware about the CSS trick but guess what this wont play well you have dependent picklist. May be its time to create a new Idea.
    – Avidev9
    Oct 23, 2013 at 18:13

You must log in to answer this question.

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