Conditional default values -- how can this be accomplished. - InfoPath Dev
in

InfoPath Dev

Conditional default values -- how can this be accomplished.

Last post 10-23-2008 09:19 AM by Jimmy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 10-23-2008 07:24 AM

    Conditional default values -- how can this be accomplished.

    I have a text field that I want to set with a default value, the default value will be one of two fields depending if they are filled in....how can I accomplish this. Its a conditional default value.  IF field1 is blank, field2, else field1     ................ How can this be done in a text field.

     

    thanks much

  • 10-23-2008 07:42 AM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Conditional default values -- how can this be accomplished.

    Hi,

     

    Add following Rule to first field:

    1. Open Fields1 properties and select Rules.
    2. Select “Set Condition”.
    3. Select Expression in first dropdown and paste following formula in second text box.

    “. != "" and ../my:field2 = ""”

    1. click on ok.
    2. Select add action and select “Set Fields value”.
    3. Select “Text Field” in second field text box and “Field1” in value text box.
     Follow the same steps to "Field2". But replace field 1 with field2 and field with field1. 
    Anuma Chinthapalli /
    http://www.GGKTech.com
  • 10-23-2008 08:29 AM In reply to

    Re: Conditional default values -- how can this be accomplished.

    Anuma, 

    It worked....Thank you so much.

    Very strange code. How did you figure this out?

    Sensational,. Thanks again.    Ed

  • 10-23-2008 09:19 AM In reply to

    Re: Conditional default values -- how can this be accomplished.

    That solution is close, but I don't think it will work too consistently.  To see what I mean:

    Preview the form.

    Enter "aaa" in field1.  Text field's value changes to "aaa" (expected)
    Enter "bbb" in field2.  Text field's value remains as "aaa" (expected)
    Delete contents of field1.  Text field's value remains as "aaa" (unexpected)
    Change contents of field2 to "bbbb". Text field's value changes to "bbbb" (expected)
    Enter "aaa" in field1. Text field's value remains as "bbbb" (unexpected)

    The italicized parts show where the behavior is inconsistent.

     To accomplish what you described in the original post, add the following rules to both field1 and field2 (it should be exactly the same two rules for both fields):
    Rule 1 - Condition: field1 [is blank]  Action: set Text field to value of field2   (when field1 is blank, the text field's value is the value of field2)
    Rule 2 - Condition: field1 [is not blank]  Action: set Text field to value of field1  (when field1 is not blank, the text field's value is the value of field1)

     

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.