2

I have an with required="TRUE". For some reason it isn't getting throwing error even if I save it without checking the box.

Here's the VF Code.

    <apex:outputPanel styleClass="margin-t3" layout="block" >
        <div class="row">           
            <div class="form-group no-margin">                                                                                                        
                 <apex:inputCheckbox required="TRUE" value="{!app.Reviewed__c}" id="Reviewed"/>
                 <label> I verify that I have reviewed this. </label>                                 
            </div>              
        </div><!--  end row -->
    </apex:outputPanel>


<apex:commandlink styleClass="btn btn-primary btn-lg" action="{!navigator}" id="nextlink" onComplete="rerunjs();" reRender="webform" status="onsubmit">
    <apex:commandButton value="Save & Continue" id="continuebutton" />
</apex:commandlink>

In the class though, I just update app. No errors and the page redirects to the next page.

I want to make the checkbox mandatory in the VF page itself. I don't want to touch apex for this. Please let me know what is wrong here.

8
  • Are you using immediate="true" somewhere on the command button for example? Commented Mar 20, 2015 at 8:48
  • Nope, im not using. I will update the command button code also here. Commented Mar 20, 2015 at 8:51
  • 1
    On the other hand how do you want to make the checkbox mandatory? Should it be implicitly checked? If a checkbox is not checked it will get a value nevertheless (false). From my point of view it is not necessary to make a checkbox mandatory. It will get a value in any case. Checked -> TRUE, not checked -> FALSE. Commented Mar 20, 2015 at 8:56
  • This is like Read Terms & Conditions checkbox. Must be checked by everyone. I used Reruired="true" Commented Mar 20, 2015 at 9:12
  • 1
    You should do the check in controller. Commented Mar 20, 2015 at 9:33

1 Answer 1

4

The required attribute doesn't work in the checkbox the way you expect. Since false (unchecked) is a valid answer, the form can submit. What you need to do is add a validation in your save code that tests the checkbox and either saves or pushes a page message to the user about the requirement to check the box.

You must log in to answer this question.

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