A mutually exclusive check box (radio button) in a repeating table/section
Clean XPath only solution. Browser forms OK.
The FORM to try.
Create following field/group structure:
Assign 0 as initial value to rStarter field. Assign following XPath expression as inital value to the ChBx field:
(xdMath:Max(../../my:CheckG/my:rStarter) = ../my:rStarter) and (../my:rStarter != 0)
Create rule at ChBx field.
This rule has 2 actions:
- Assign rStarter to 2 * (. != “false”)
- Assign rStarter to 1 * (. != “false”)
Place control you like (check box or radio button) on the layout. For check box default “Value when cleared” to false and “Value when checked” to true. For radio button limit amount of choices to 1 and set “Value when selected” to true.
Form with more complex behaivior (excludes rows of the same category only, also not tested in SP2010)
Thats it. Happy codeless programming!
P.S. Actually that form looks as potentially a good example to demonstrate field updating concepts like “push” and “pull” and how they are interrelate with each other. In particulary it would be interesting to explain why the sequence of operators like i=2; i=1; which have no sense in any language can be useful thing in Infopath. (Kind of a statement, eh? But that’s fine, hopefully people familiar with volatile variables concept and multithreading are not reading posts about InfoPath :) )
Hi,
I can not get this to work properly in my own infopath form.
Can you please provide a step-by-step on how to do this.
I have set the right default values and rules (I think), but when I test it, I can check all the rows and not only one…
So, I think I have missed something… I am using InfoPath 2007
Best regards Sun
Sun - September 22, 2009 at 7:41 am |
Done.
alecpojidaev - September 22, 2009 at 2:56 pm |
Thank you!
Bet Regards Sun
Sun - September 23, 2009 at 7:43 pm |
Hello again…
I have problems getting this to work, even if I follow your step by step.
I managed to get it to work in one test form, but in the production form it doesnt work – I can check every row in the repeating table…
The value of the rStarter = 1 on every row when I click the optionbutton ( no swichting back to 0 when I check another row).
Have you experienced this? And how did you solve it?
I have set the rules and the default value ((Starter=max(rStarter)) and (rStarter != 0)), the optionbutton value when selected = true, the default value of rStarter=0.
Best Regards Sun
Sun - September 30, 2009 at 12:03 pm |
You have to copy full XPath:
(../my:rStarter = xdMath:Max(/my:myFields/my:CheckG/my:rStarter)) and (../my:rStarter != 0)
alecpojidaev - September 30, 2009 at 1:25 pm |
Thanks for a quick response.
I clicked verify formula and got the “short version” of the xpath. So does that really matter?
BR Sun
Sun - September 30, 2009 at 3:05 pm |
The short relative path evaluates to just one current node. The long absolute path makes max() function to evaluate all rStarter nodes. You still can use relative path in max() function but it has to include the parent group node like this: ../../my:CheckG/my:rStarter
alecpojidaev - September 30, 2009 at 3:43 pm |
ok, thank you for your patience, I will try it again.
BR Sun
Sun - September 30, 2009 at 4:24 pm
I finally got it to work – thank you for the help.
I used Insert formula dialogbox… that was a big NO NO :=)
Thanks again
Best Regards Sun
Sun - September 30, 2009 at 6:22 pm |
I have followed the steps above exactly, but am not able to select any checkbox or radio button. What could I have done wrong? Thanks!
Jessica - October 6, 2009 at 4:37 pm |
Have you specified control values? They have to be true for checked and false for unchecked.
Also there is a link to the example of the form so you could compare your design with this primer.
alecpojidaev - October 6, 2009 at 6:16 pm |
Hi Alec – again =)
Can I ask you another question – about checkboxes in a repeating table?
I have a Submit button, that is to be disabled unless there is at least one row that is checked in the repeating table.
It is a multiselect repeating table, with only 2 fields one is True/false (for the checkbox) and the other is a text field.
I need to set conditional formatting on the submit button, so if there is no checkbox selected the button is disabled.
Is this something you can help me with?
Best Regards Sun
Sun - October 8, 2009 at 10:46 am |
Sure. In conditional formatting section paste following expression :
not(xdMath:Max(my:CheckG/my:rStarter))
then check “Disable this control” checkbox.
alecpojidaev - October 8, 2009 at 1:25 pm |
Thank you thank you thank you =)
Sun - October 8, 2009 at 1:36 pm |
Hallo again…
It worked great in the InfoPath client but not as a webbrowser form…
any suggestions?
Maybe I did it the wrong way, in the conditional formatting section for the button:
selected the CheckG “is equal to” not(xdMath:ax(my:CheckG/my:rStarter)), and checked the “Disable this control”
BR Sun
Sun - October 8, 2009 at 2:38 pm |
Try different expression:
count(my:CheckG[my:ChBx = “true”]) = 0
alecpojidaev - October 8, 2009 at 2:47 pm |
And yes no need to choose is “is equal”. Instead of “Choose field or group” pick “expression” and paste one of my formulas.
alecpojidaev - October 8, 2009 at 2:50 pm |
The Count(….) worked =D
Thanks again
Sun - October 8, 2009 at 3:19 pm |
Hi Alec,
First of all I want to thank you for coming up with tutorials such as this one. You’re a great help to newbies like myself.
I tried your example here and it works great. However, I’m not sure how to apply the method you presented here to my own form because it is based on Access database. Should I add extra field to my Access database to serve as rStarter field? Another thing is my checkbox field is of boolean type while yours is text. I would be very much grateful for any help you’ll extend. Thank you in advance.
Jett
Jett - January 22, 2010 at 3:12 am |
1) Yes, you will need additional field for rStarter.
2) Type of the field doesn’t matter as long as your expression is able to interpret that field value in a right way.
alecpojidaev - January 22, 2010 at 2:13 pm |
Thanks for the prompt response Alec. I’m not sure I know how to do the second part of your reply regarding the type of field. Because I tried to change your sample form converting the ChBx to boolean type and it’s not working. Obviously, I need to change the formula which I’m not sure how. Being a noob, I couldn’t understand the original formula let alone change it. I’m sorry but I’m afraid I certainly gonna need your assistance here to come up with the right formula.
Jett - January 22, 2010 at 3:15 pm |
The reason why I used text type for the check box is the text type allows to enter formulas as default values. So to be able to emulate functionality you will need to add 2 text fields to your Access datasource and remove or ignore boolean type field.
alecpojidaev - January 22, 2010 at 3:48 pm
Thanks for putting up with me. I really really appreciate it. Anyways, so I created a sample form based on an Access DB and I got it to work with “Active” (my “ChBx” field) as a text field. Thanks Alec! You’re the best!
I’m not done yet though. My “versioning” form needs as the final requirement, that checking on a check box will disable other rows that are of the same RecordNo as that of the current and not those that aren’t. Hope the following illustration clears any confusion:
ID RecordNo Version Active Starter
1 001 1.00 false
2 001 2.00 true
3 002 1.00 true
4 003 1.00 false
5 003 2.00 false
6 003 3.00 true
So in this scenario, checking ID 4 should only uncheck ID 6 and not IDs 2 & 3. Does I make sense? :)
Hope you can help me out with this problem. This is the last piece of the puzzle that I need to finally complete the project I’m doing for my practicum. This will definitely help my chances of finally getting a job. If ever, you’re gonna be my hero. Thanks again.
Jett - January 22, 2010 at 10:06 pm |
If by desabling row you mean desabling all controls of that row you may apply following conditional formatting for each active control:
my:RecordNo = /my:myFields/my:CheckG[my:rStarter = 1]/my:RecordNo
alecpojidaev - January 22, 2010 at 10:34 pm
Sorry… let me rephrase that:
My “versioning” form needs as the final requirement, that checking on a check box will uncheck other rows that are of the same RecordNo as that of the current and not those that aren’t.
Jett - January 23, 2010 at 4:11 am |
Sorry, I don’t fully understand your business process here. When the same RecordNo rows become checked? Is it interactive or it’s comming from DB?
alecpojidaev - January 23, 2010 at 6:56 pm
I’m sorry for not explaining clearly enough. I’m not so good with english. Anyways, my form is hooked to an Access database as main datasource. The form will be used to manage articles where each article will have 1 or more versions. There should be only one “Active” version per article and the “Active” checkbox on each row is supposed to serve that purpose. So for example there are 2 versions of article 001, checking on Version 1.00 will uncheck Version 2.00. However, this should not affect the other articles (002 & 003) which have their own sets of versions. In the illustration below, since there are 3 articles, there should also be 3 checked “Active” fields.
ID__ArticleNo__Version__Active__Starter
1___001________1.00_____false___
2___001________2.00_____true____
3___002________1.00_____true____
4___003________1.00_____false___
5___003________2.00_____false___
6___003________3.00_____true____
I created a test database and form and so far I’m ending up with only 1 active record as it also unchecks all the rest regardless of the ArticleNo which is not correct.
Hope this clears things up. If something still unclear please let me know. I can also send you my test form and database if you want. Thank you so much for putting up with me.
Jett - January 23, 2010 at 10:00 pm |
Hi Alec,
I’m really sorry for messing this “comments” section of your blog. I was looking for ways to remove my comments last january 23rd but unable to. Anyways, I’m sure you as the owner of this blog has a way of doing so. I sincerely apologize for that.
So back to my problem, I modified my test form and database to clear up the confusion. I changed the field “Record” to “Article” because even I got confused and had difficulty getting the idea across.
My form is hooked to an Access database as main datasource. The form will be used to track articles where each article will have 1 or more versions. There should be only one “Active” version per article and the “Active” checkbox on each row is supposed to serve that purpose. So for example there are 2 versions of “Code” article, checking on Version 1.00 will uncheck Version 2.00. However, this should not affect the other articles (“Issues” & “Formula”) which have their own sets of versions. In the illustration below, there are 3 articles (“Code”, “Issues” & “Formula”) and each article have one active version which is correct.
ID__Article__Version__Active__Starter
1___Code_____1.00_____false___
2___Code_____2.00_____true____
3___Issues___1.00_____true____
4___Formula__1.00_____false___
5___Formula__2.00_____false___
6___Formula__3.00_____true____
So far with my test database and form, I can check on a version and this unchecks all the rest which means I was able to make your concept to work. But I need to come up with some modification to your formula so that checking on an article’s version will uncheck only those versions belonging to the same article.
Hope this clears things up. If anything needs clarification please let me know. I can also send you my test form and database so you can test it out.
This is the last thing my form needs to complete it. I really need your help. Thank you so much for putting up with me.
Jett - January 25, 2010 at 4:33 pm |
Thats fine to post anything here as long as it’s related to the article. I will try to come up with solution for you but that might take some time.
alecpojidaev - January 25, 2010 at 4:38 pm |
Thanks. I know you have your own concerns as well. I completely understand that. Thank you very very very much…
Jett - January 25, 2010 at 4:51 pm
Initial value for ChBx:
(../my:rStarter = ../my:RecordNo) or (../my:RecordNo = -../my:rStarter and (/my:myFields/my:CheckG[my:rStarter = xdMath:Max(/my:myFields/my:CheckG/my:rStarter)]/my:RecordNo != ../my:RecordNo or xdMath:Max(/my:myFields/my:CheckG/my:rStarter) <= 0))
alecpojidaev - January 25, 2010 at 7:16 pm
Actions at ChBX:
substring-before(substring-after(concat((. = "true") and ../my:rStarter = 0, ../my:RecordNo, "true", ../my:rStarter, "true"), "ue"), "true")
substring-before(substring-after(concat((. = "true") and ../my:rStarter > 0, -../my:RecordNo, "true", ../my:rStarter, "true"), "ue"), "true")
substring-before(substring-after(concat((. != "true") and ../my:rStarter < 0, "0", "true", ../my:rStarter, "true"), "ue"), "true")
alecpojidaev - January 25, 2010 at 7:24 pm
The form to test
alecpojidaev - January 25, 2010 at 8:33 pm
You did it Alec! It works! You’re a genius. You’ve just become my personal hero. I will be forever grateful to you. Thank you very very very much!
Jett - January 26, 2010 at 3:34 am
This is a brilliant way of doing it..No code behind needed. Thank you.
Hassan Mia Salie - December 2, 2010 at 3:25 pm |
just started following your wark and it is amazing. I am struggling trying to solve this one. I have IP 2010 Browser form. This functions perfectly in the client. When I publish it out and test it in the browser, it fails. Any suggestions how to make this work in 2010 browser forms?
Larry - July 18, 2011 at 7:16 pm |
It was tested as browser enabled form for SP 2007. Right now I have access to SP 2010 standard only. I’ll test it out when I’ll have a chance.
alecpojidaev - July 18, 2011 at 7:27 pm |
Thanks for the quick reply. I did notice it was setup as browser 2007, I did not publish it out this way because my form is a 2010. I appreciate you time and following up. thanks
Larry - July 18, 2011 at 7:32 pm
Hello
Thanks a ot for a very good blog.. i tried it on my form.. but its not working.. My repeating table is structure is like that
Main/group1/group2/group3… Group3 is repeating table and it is filling using code. i have applied all rules and set values as you have set in your form but its not working. Can you please help me.
Hammad Umar - July 21, 2011 at 7:06 am |
I’ve uploaded a new form.
alecpojidaev - July 21, 2011 at 6:21 pm |
New form is uploaded
alecpojidaev - July 21, 2011 at 7:33 pm |
Thanks its working.. good work…
Hammad Umar - July 22, 2011 at 3:44 am
Well, that looked like an easy fix. you just swapped two items in that default value. Bravo! great job
Larry - July 21, 2011 at 9:45 pm |