This, that and the other (may contain nuts)

XPages: Validating Radio Groups Client Side

Steve Castledine  February 17 2010 03:45:48 AM
This has come up twice recently so thought I would share a few tips.

Server side validation of radio groups and also check box groups on a basic level is very simple. You navigate to the component properties and add a "required" (xp:validateRequired) validation rule via data > validators.

I say simple however other components do have this available on a specific validation tab whereas these you have to drill down to the properties:

Image:XPages: Validating Radio Groups Client Side
If you want to do more advanced validation then the value is available via getComponent("radiogroup").getValue(). Depending on where on the page you are trying to validate the value (maybe before the component) you may need to use getSubmittedValue() instead but mostly getValue() is what you would use.

Client side is a little trickier, as just like any web application and javascript accessing of radio group values its not available as a single value but as independent values of the radio group (or check box) child values.

To make it harder you have to get values via the "form" element and even harder I find JSF style name's are not liked in browsers for looking up named elements of a form (at least it was a struggle for me) so you have to traverse the entire form to get the element you need and then get the value you want.

The code below is an example of what I mean. First it goes through all the form elements to find what we need, then it iterates through the child elements to find the value. Note how it uses #{id:myRadioGroupID} to calculate the eventual component name (which may actually be: view:_id1:myRadioGroupID).

var result=null;

for(var i=0; i<document.forms[0].elements.length; i++){

if(document.forms[0].elements[i].name=="#{id:myRadioGroupID}" ){

if(document.forms[0].elements[i].checked == true){
        result=document.forms[0].elements[i].value;
        break; //remove this if for check box groups and collect multiple values above instead
}}}

alert(result);

Comments

1Sudatta  7/29/2010 6:21:51 AM GMT -6  XPages: Validating Radio Groups Client Side

Hi Steven,

How to validate a checkbox core control using client side javascript in x-pages?

and how to validate a checkbox group control using client side javscript?

Regards,

Sudatta

2Kev Gill  6/2/2011 3:58:49 AM GMT -6  XPages: Validating Radio Groups Client Side

There is an easier way to get to the radio group buttons via:

var id = window.document.getElementById("#{id:myRadioGroupID}");

var rb1 = id.elements[0].checked;

var rb2 = id.elements[1].checked;

3Dwain A Wuerfel  6/13/2011 9:16:46 PM GMT -6  XPages: Validating Radio Groups Client Side

Kev,

I am no expert in xPages or javascript, but from what I have read from others that are what you have is great if the radio button has static values. However, if you are pulling in the options dynamically from a keyword document I don't believe this will work.

4  4/1/2015 3:02:23 PM GMT -6  XPages: Validating Radio Groups Client Side

5  4/1/2015 3:02:23 PM GMT -6  XPages: Validating Radio Groups Client Side

6cialis  4/15/2015 5:06:25 PM GMT -6  cialis

Hello!

<a href="{ Link } ,

7impotence  4/16/2015 2:33:56 AM GMT -6  cheap impotence drug generic cialis delivery

Hello!

<a href="{ Link } impotence drug generic cialis delivery</a> ,

8cialis  4/19/2015 11:03:46 AM GMT -6  cialis

Hello!

<a href="{ Link } ,

9cialis  4/19/2015 4:01:47 PM GMT -6  cheap cialis online

Hello!

<a href="{ Link } cialis online</a> ,

10online  4/22/2015 10:28:01 AM GMT -6  cialis online pharmacy

Hello!

<a href="{ Link } viagra</a> , <a href="{ Link } online pharmacy</a> ,

11cialis  4/25/2015 5:46:43 AM GMT -6  cialis

Hello!

<a href="{ Link } , <a href="{ Link } ,

12online  4/27/2015 9:03:02 AM GMT -6  viagra online pharmacy

Hello!

<a href="{ Link } online pharmacy</a> , <a href="{ Link } pills</a> ,

13purchase_viagra  4/27/2015 11:47:24 AM GMT -6  purchase viagra

Hello!

<a href="{ Link } viagra</a> , <a href="{ Link } cialis</a> ,

14online  4/27/2015 11:03:13 PM GMT -6  viagra online pharmacy

Hello!

<a href="{ Link } online pharmacy</a> , <a href="{ Link } pills</a> ,

15purchase_viagra  4/28/2015 1:40:22 AM GMT -6  purchase viagra

Hello!

<a href="{ Link } viagra</a> , <a href="{ Link } cialis</a> ,

16discount_viagra  5/1/2015 1:17:12 AM GMT -6  discount viagra

Hello!

{ Link } , , { Link } , ,

17to  5/2/2015 12:43:26 AM GMT -6  where to buy cialis onlinebuy cheap cialis online

Hello!

{ Link } , , { Link } , ,

18without  5/6/2015 10:46:55 AM GMT -6  cialis without prescription

Hello!

{ Link } , , { Link } , ,

19viagra_pills  5/8/2015 10:04:14 PM GMT -6  viagra pills

Hello!

{ Link } , , { Link } , ,

20cialis_price  5/15/2015 2:22:28 PM GMT -6  cialis price

{ Link } , { Link } ,

21cialis_pills  5/15/2015 9:23:47 PM GMT -6  cialis pills

{ Link } , { Link } ,

22online  5/17/2015 9:34:30 AM GMT -6  viagra online pharmacy

{ Link } , { Link } ,

23pharmacy  5/17/2015 3:10:06 PM GMT -6  online pharmacy viagra

{ Link } , { Link } ,

24female_viagra  5/17/2015 8:32:57 PM GMT -6  female viagra

{ Link } , { Link } ,

25viagra  5/21/2015 2:04:48 PM GMT -6  viagra

{ Link } , { Link } ,

26without  6/19/2015 7:50:40 AM GMT -6  cialis without prescription

{ Link } , { Link } ,

27viagra  7/6/2015 10:36:51 AM GMT -6  generic viagra online

{ Link } , { Link } ,

28fast  7/8/2015 12:03:50 PM GMT -6  cialis fast delivery

{ Link } , { Link } ,

29online  7/10/2015 10:24:02 AM GMT -6  cialis online pharmacy

{ Link } , { Link } ,

30viagra  7/17/2015 2:24:42 PM GMT -6  viagra

{ Link } , { Link } ,

31fast_delivery  7/18/2015 9:16:06 AM GMT -6  fast delivery

{ Link } , cialis ,

32viagra  7/19/2015 6:47:28 AM GMT -6  viagra

{ Link } , cialis ,

33viagra  7/21/2015 10:01:15 AM GMT -6  buy viagra online from canada

{ Link } , { Link } ,

34viagra  7/23/2015 12:40:53 PM GMT -6  viagra

Hello!

{ Link } , , { Link } , ,

35cheap_tadalafil  7/23/2015 4:12:55 PM GMT -6  cheap tadalafil

{ Link } , { Link } ,

36buy_viagra  7/24/2015 1:51:42 AM GMT -6  buy viagra

Hello!

{ Link } , , { Link } , ,

37viagra_price  8/22/2015 5:35:14 AM GMT -6  viagra price

{ Link } , { Link } ,

38viagra  8/29/2015 7:45:27 AM GMT -6  viagra

{ Link } , { Link } ,

39cialis  9/6/2015 2:58:24 PM GMT -6  discounted cialis 20 mg

Hello!

{ Link } , , { Link } , ,

40without  9/12/2015 5:42:02 PM GMT -6  viagra without prescription

Hello!

{ Link } , , { Link } , ,

41online  9/23/2015 7:33:16 PM GMT -6  cialis online buy cialis without prescription

{ Link } , { Link } ,

42canadian_cialis  10/7/2015 11:55:43 AM GMT -6  canadian cialis

{ Link } , { Link } ,

43generic  10/8/2015 3:50:24 AM GMT -6  fedex generic viagra

{ Link } , { Link } ,

44generic_viagra  10/28/2015 3:09:56 PM GMT -6  generic viagra

Hello!

{ Link } , , { Link } , ,

45sublingual  10/29/2015 2:32:56 AM GMT -6  buy sublingual cialis online

Hello!

{ Link } , , { Link } , ,

46suppliers  10/29/2015 3:47:21 PM GMT -6  viagra suppliers in the uk

Hello!

{ Link } , , { Link } , ,

47viagra  11/7/2015 6:25:44 PM GMT -6  buy viagra without prescription

{ Link } , { Link } ,

48without  11/13/2015 5:51:32 AM GMT -6  cialis without prescription

{ Link } , { Link } ,

49viagra  11/17/2015 4:25:07 PM GMT -6  viagra

{ Link } , { Link } ,

50viagra_samples  11/18/2015 1:26:59 AM GMT -6  viagra samples

{ Link } , { Link } ,

51online  11/18/2015 2:09:41 PM GMT -6  cialis online sale

{ Link } , { Link } ,

52buy_viagra  12/24/2015 8:20:08 AM GMT -6  buy viagra

Hello!

{ Link } , , { Link } , ,

53cialis  12/24/2015 4:50:11 PM GMT -6  buy cialis canada

Hello!

{ Link } , , { Link } , ,

54order  12/25/2015 12:34:37 AM GMT -6  mail order viagra

Hello!

{ Link } , , { Link } , ,

55restpharm  8/24/2016 6:05:05 AM GMT -6  restpharm

Hello!

{ Link } , ,

56Nikki  2/7/2017 6:27:40 AM GMT -6  XPages: Validating Radio Groups Client Side

Very large dogs, the parody of Russia. I advise you to read about it on this site a lot of pictures and interesting facts about it

{ Link } Caucasian Shepherd