Contingent validation: if "other" you must describe
Jul 21, 2010
In traditional Notes development, it's a fairly simple thing to only require a value in field "B" if field "A" has a certain value. I use this when I give people an opportunity to select "Other" for some reason: I then require to know what the "Other" is. I'm working on this for a XPage, but where it's even easier there than in traditional Notes to put in some validation, I couldn't find an example of how to require a second field only if a previous field had a certain value. As often as I use it in my workflow, I was a bit surprised not to find any examples. I did eventually discover an answer. It may  not be the best one, and if anyone has a better suggestion, please post it. I'm posting what I have because I hope it'll help out someone else who was in the position I was this morning.

The code I'm using is based on some developed by 
Wei CDL Wang, in a post on OpenNTF. I'm using Wei's code for checking for the existence of an attachment as well. What this does is from the client side (i.e. don't turn off client side validation for this) it gets the values of both fields. If the first field has a value of "Other", the second field must have something in it, or there is an alert box that pops up. Returning false prevents the server side from executing.

<xp:button value="Label" id="button1">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="complete" immediate="false" save="true">
var comboVal = document.getElementById("#{id:comboBox1}").value;
var otherVal = document.getElementById("#{id:inputText1}").value;
if(comboVal == "Other" & (otherVal == "" || otherVal==null )){
    alert("Please define the type of other document this is. ");
    return false;
} else {
return true;

I'm loving lots of this XPage stuff, but every so often something that was simple in traditional Notes development isn't covered. I had started out looking in Designer Help, and I can't find anything in there. I really miss the cross reference available in previous versions: you could look up @DBLookup and it would refer you to GetDocumentByKey in LotusScript.

Now that I have it, the next one will be easier, so on to the next one!

This is an archive of my previous blog attachments are in the download control