0

PS: this is not duplicate all others who posted the link is not using the apex:pageBlockTable as i appose to using in this question, the links you guys have posted are using apex:pageBlockSection

I have a page that defines an inputText with required="true" but when the page renders, the input box doesn't have the red bar indicating that it's required.

Screen shot: enter image description here

Tried with apex:inputField as well.

<apex:pageBlockTable value="{!pWraps}" var="pWrap" id="pResults" rendered="{!pWraps.size>0}" >                     
  <apex:column headerValue="Quantity" >
    <apex:inputField value="{!pWrap.quantity}" required="true" />                    
  </apex:column>
</apex:pageBlockTable>  
7
  • Input field should work. But you need to make sure you have 2 columns as the required CSS is on the label, not the field. For inputText I'm pretty sure you have to roll your own CSS.
    – gorav
    Sep 14, 2016 at 1:56
  • 2
    Possible duplicate of Required field mark (Red Vertical Bar) not coming
    – Eric
    Sep 14, 2016 at 1:57
  • Eric, the url you have posted is not using the apex:pageBlockTable
    – Nick
    Sep 14, 2016 at 2:00
  • @NickKahn - No, but the answer is still the same, you will have to roll your own. I am not entirely sure of the exact situations when it shows without rolling your own, only that it is limited to specific situations, all others you need to do it yourself
    – Eric
    Sep 14, 2016 at 2:02
  • What do you mean roll your own? you mean CSS?
    – Nick
    Sep 14, 2016 at 2:05

1 Answer 1

2

This is by design. The required attribute simply makes the field required for the Ajax request.

In order to have the red mark the element needs to be the child of a pageblockscetion or sectionitem IIRC.

For example, this does display the red mark without any issue:

<apex:page standardcontroller="Account">


    <apex:form >
        <apex:pageBlock>
            <apex:pageblockSection>

                <apex:pageblockSectionItem>
                    <apex:inputField value="{!Account.Name}" required="true"/>
                </apex:pageblockSectionItem>

            </apex:pageblockSection>
        </apex:pageBlock>    
    </apex:form>
</apex:page>

For other elements you may have try out the info here:

http://itsmersaini.blogspot.com/2014/11/adding-required-red-mark-on-vf-page.html

Enclose your text box in div with class requiredInput and put another div with class requiredBlock where you want to show Red mark.

Page: testRequiredField

<apex:page controller="AccountCustomController" >
  <apex:form >
    <apex:pageBlock title="Quick Edit: {!account.Name}">
            <apex:pageBlockSection title="Account Details" columns="1">
                <div class="requiredInput">
                    <div class="requiredBlock"></div>
                    <input type="text" value="Fill your name here"  /> 
                 </div>               
             </apex:pageBlockSection> 
   </apex:pageBlock>
  </apex:form>
</apex:page> 

Basically you will have to wrap each inputField in the two divs

I have done it with jQuery / css before like this:

On document Ready:

$('.req_blk').each(function(){

        $(a).parent("td").prepend("<div class='requiredBlock'></div>");
        $(a).parent("td").contents().wrapAll("<div class='requiredInput'/>");

});

then put the class req_blk on each input field that I wanted to mark required. There may be better ways though......

Using a PageBlockTable

<apex:page standardcontroller="Account" recordSetVar="accts">


    <apex:form >
        <apex:pageBlock>
            <apex:pageBlockTable value="{!accts}" var="a">                     
              <apex:column headerValue="Name" >
                <div class="requiredInput">
                    <div class="requiredBlock"></div>
                    <apex:inputField value="{!a.Name}" required="true" />                    
                </div>
              </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>    
    </apex:form>
</apex:page>

enter image description here

5
  • have you tried in apex:pageBlockTable i just tried and i do not see at all
    – Nick
    Sep 14, 2016 at 2:03
  • @NickKahn - See updated answer
    – Eric
    Sep 14, 2016 at 2:08
  • Eric: does not work, please try using pageBlockTable you will see what I'm talking about.
    – Nick
    Sep 14, 2016 at 2:11
  • @NickKahn - yes it does, see bottom of updated answer
    – Eric
    Sep 14, 2016 at 2:16
  • 1+ Thank you so much and I really appreciate.
    – Nick
    Sep 14, 2016 at 2:18

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.