I recently had the need to add validation to radio buttons, check boxes and list boxes for an XPages app. Sounds straightforward, surely it’s just the same as for any other control. However, I was creating the Radio button group, Checkbox group and List Box controls for Domino documents in a repeat control. So for each document, the output might need to be a Radio button group, or a Checkbox group, or a List Box, or some other input control. And furthermore the control might be mandatory or not, and the validation message was also configurable.

So within my repeat control I was using a script block to create a function using XSP.attachValidator depending on whether or not the control should mandatory, passing the relevant message. I was then using XSP.addOnLoad to run the function at run time. This worked most of the time, but for these particular controls I got an error message after the validation ran:
Validation Error

There are a number of possible options (including extending the XSP.validationError function), depending on the complexity of what is required and the output you want. I will run through these in the following parts of this, building up the rather complex solution I implemented herewhere absolute flexibility is required.*

* Please be aware, this is piggy-backing on the Preview function I use, so it recreates the relevant documents each time the link is triggered, so if someone else triggers the link, your answers will be lost. Also, note the normal XSP validation gets triggered on the text box and drop-down, before the server-side script runs to validate the radio button, checkbox and listbox.

 
Option One: Add a Required Validator

This may be useful if you only want a basic error message. From the Properties pane you can add a Required Validator. The code lets you enter a message here, as you see.

However, with 8.5 (I don’t know about 8.5.1), your text added for the ‘message’ property is ignored, and you get this:

Error Message Outcome

That’s not great, so in the next part we’ll go onto other options.

2 thoughts on “XPages: Validation for Radio Buttons, Check Boxes and List Boxes: Part One”

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top