API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Getting Multiple Radio Buttons To Act Like One
Recently, while developing an application, an interesting situation came up. The customer wanted a description, then a radio button, then another description, then the second radio button. So there's two radio buttons separated by a few lines of text. In the HTML world, this situation is easy to handle - radio buttons can appear anywhere and as long as they are all given the same name, clicking on one radio button will uncheck the other and vice versa. But this application was in the Notes 5 client, which doesn't recognize HTML. So what did we do?

To solve this problem, it took a little knowledge of how the Notes client computes fields. Remember that when a document is being refreshed, fields are computed top to bottom, left to right. We can use this to our advantage. Let's say you have two radio button fields called Field1 and Field2. Set up the fields to refresh the document on keyword change. So when you click on a radio button, the document will be refreshed. Each radio button should have only 1 value, and the value doesn't matter to the code.

The next thing we need to do is to know which radio button is changing, so we can clear out the other one. (If you click on Field1, then clear out Field2 and vice versa). Since we're dealing with only 2 fields here, we can keep track of one and make the assumption about the other. So create a field called PrevField1. It should be a text field, and computed for display with a value of Field1. This field can be hidden and can appear either above the radio button fields or below the radio button fields. The position of this field isn't as crucial as the second field we'll be creating.

Create another computed for display text field called UncheckOtherRadio. This field can also be hidden, but it MUST appear ABOVE the radio button fields. If you put PrevField1 above the radio button fields, then UncheckOtherRadio must appear above PrevField1 as well. It has to appear above because of the way Notes recalculates fields - top to bottom, left to right. When this field is being recacluated, the radio button fields will have been changed (because the change of the radio button field is what is kicking off the refresh). Since it appears above PrevField1, PrevField1 will not have been refreshed yet, so it will have the old value of Field1. If PrevField1 is different than Field1, then we know that what radio button was just clicked.

So, the formula for UncheckOtherRadio is:

FIELD Field1 := Field1;
FIELD Field2 := Field2;
@If(Field1 = "" | Field2 = ""; ""; PrevField1 = ""; @SetField("Field2"; ""); @SetField("Field1"; ""))

First, the @SetField function needs to have the fields defined so do that. The last line is where things get interesting. If either radio button is blank right now, then there's nothing further that needs to be done. This will handle the situation that something besides clicking on one of these radio buttons is causing the document to refresh.

If both the radio buttons are not blank, then one needs to be cleared. If PrevField1 is blank, then we know that Field1 was just clicked on, so clear the value for Field2. If PrevField1 is not blank, then it must be that Field2 was just clicked on, so clear the value of Field1.

There you go. Two radio button fields that act like they are one. So the Notes 5 client can have radio buttons that are separated on the screen but still function as one.