Alec Pojidaev's InfoPath Blog
Stuff published for no reason (cool codeless infopath solutions mostly)

A mutually exclusive check box (radio button) in a repeating table/section

Bookmark that post

Clean XPath only solution. Browser forms OK.
The FORM to try.

Create following field/group structure:

fields
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 :) )

About these ads

43 Responses to “A mutually exclusive check box (radio button) in a repeating table/section”

  1. 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

  2. Thank you!
    Bet Regards Sun

  3. 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

  4. Thanks for a quick response.
    I clicked verify formula and got the “short version” of the xpath. So does that really matter?

    BR Sun

    • 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

  5. 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

  6. 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!

  7. 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.

  8. 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

  9. Thank you thank you thank you =)

  10. 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

  11. The Count(….) worked =D

    Thanks again

  12. 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

    • 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.

    • 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.

      • 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.

    • 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.

      • 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

    • 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.

      • 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?

  13. 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.

  14. 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.

    • 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.

      • Thanks. I know you have your own concerns as well. I completely understand that. Thank you very very very much…

      • 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))

      • 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")

      • 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!

  15. This is a brilliant way of doing it..No code behind needed. Thank you.

  16. 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?

    • 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.

      • 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

  17. 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.

  18. Well, that looked like an easy fix. you just swapped two items in that default value. Bravo! great job


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 40 other followers

%d bloggers like this: