Creating multiple-condition rules for option buttons - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Creating multiple-condition rules for option buttons

Last post 11-10-2009 01:48 PM by warrtalon. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 10-30-2009 12:04 PM

    • nitsuj
    • Not Ranked
    • Joined on 10-30-2009
    • Posts 4

    Creating multiple-condition rules for option buttons

    Hi,

    I'm trying to do something which seems simple but I can't seem to find the answer.  Basically, I have 9 option buttons (well, 18 buttons total, with Yes and No buttons bound to 9 fields) with values of Yes/No.  I want a text box to display "Yes" if all of the option buttons have values of "Yes", and "No" if any of the buttons are set to "No".  I've tried creating a rule that says "If button1 = yes AND button2 = Yes (and so forth), then text box = "Yes", but it doesn't seem to work for more than one option button.

    I know rules can only have 5 conditions, so I was going to chunk them up into two additional Yes/No fields, but I would still run into the same problem.  Anybody know what I may be doing wrong, or what (preferably codeless) alternative I can try?

    Thanks!

  • 10-30-2009 04:18 PM In reply to

    Re: Creating multiple-condition rules for option buttons

    Hi -

    Have you thought about having your options be 1 and 0? Then you could sum all the fields and if the total = 9 (9 fields, right?) your text box could be Yes. If the total is less than 9, your text box could be No. (As an aside, if you don't need to store that value for anything, perhaps use a couple of expression boxes instead and conditionally format them?)

    That being said, what you suggested should work. I'd guess your issue might be with case (if your option has a value of 'yes' and your condition is 'Yes', that would evaluate to false). You may want to verify the values for each button are what you think, case included, and try again....

    Oh, and the 5 conditions thing? You can work around that. Change the first dropdown in your condition to 'The expression' then type away, like this:

    my:field1 = 'yes' and my:field2 = 'yes' and my:field3 = 'yes' ....

    That's three conditions right there, but only using up one line in your 'allowed' 5 conditions...

    Hilary Stoupa

  • 10-31-2009 01:49 PM In reply to

    • nitsuj
    • Not Ranked
    • Joined on 10-30-2009
    • Posts 4

    Re: Creating multiple-condition rules for option buttons

    Thank you for the reply!

    I actually need the 9 Yes/No fields to be Yes/No, so the 1/0 idea probably wouldn't work for me.  I also need the value of the final Yes/No text box, so it does need to be text instead of an expression.

    I hadn't thought about writing an expression instead of setting multiple conditions, so I tried it out but it still doesn't seem to want to work.  Here's the curious thing: when I try to set the rule for the final Yes/No text box (i.e. if optionButton1 = "Yes" then set this box to "Yes", etc) it doesn't work.  But if I set the condition on the option button itself (i.e. if this button = "Yes" then set the final text box to "Yes"), then it works.  Trying to throw in additional option buttons to the expression causes it not to work though, and setting a rule for each of the option buttons wouldn't be right since I need ALL of them to be "Yes" for the final text box to be "Yes".

    Thanks for your help so far.  I'll keep messing it and see if I can figure out what I'm doing wrong.

    Thanks!

  • 10-31-2009 05:27 PM In reply to

    Re: Creating multiple-condition rules for option buttons

     Rules only have any effect when the field they are attached to changes value.  They won't fire if some other field that's referenced in the rule changes value.

     Try this:

    Set the default value of your final text box to be something like this:

    (optionButton1 = 'Yes' and optionButton2 = 'Yes', etc...)
    This will cause it to take on a value of 'true' or 'false when one of the option buttons changes.
    Then add two rules to the field of that text box:
    Condition: finalField = true
    Action: Set finalField to the value Yes
    Condition: finalField = false
    Action: Set finalField to the value No
    This will immediately change the value of the field to Yes or No when one of the option buttons causes it to change to true or false.
    Also add precisely the same two rules to the set of form load rules to set the initial value of the field.
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-01-2009 01:23 PM In reply to

    • nitsuj
    • Not Ranked
    • Joined on 10-30-2009
    • Posts 4

    Re: Creating multiple-condition rules for option buttons

    Jimmy, you're awesome!!  That worked!

    Thanks so much for your help!

  • 11-10-2009 12:33 PM In reply to

    • nitsuj
    • Not Ranked
    • Joined on 10-30-2009
    • Posts 4

    Re: Creating multiple-condition rules for option buttons

    Hi everyone, one more quick question regarding this...

    Is there a way for the final text box to have a third state?  For instance, can I somehow have the text box default read "Unknown" until one of the preceding option buttons gets clicked, at which point the text box will read "No", until all option buttons are clicked "Yes", at which point the text box will also read "Yes"?

    I could see this possibly working if I could say "optionButton1 = stateless and optionButton2 = stateless" then text box = "Unknown".  I'm sure "stateless" is wrong, but something close to it.

    Thanks again in advance!

  • 11-10-2009 01:48 PM In reply to

    Re: Creating multiple-condition rules for option buttons

    You can set the default value as Unknown, and then when option buttons are selected, fire a rule that sets it to No if not all buttons are selected and it's not already set to No, but set it to Yes if all buttons are selected and it's not already set to Yes.  Each button would have the same rules.

Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.