Data Validation on multiple fields - InfoPath Dev
in

InfoPath Dev

Data Validation on multiple fields

Last post 06-28-2011 11:26 PM by eliasen. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 06-28-2011 06:24 AM

    • eliasen
    • Top 500 Contributor
      Male
    • Joined on 10-07-2010
    • Aalborg, Denmark
    • Posts 33

    Data Validation on multiple fields

    Hi all

    I have two textboxes bound to a data source field each.

    I need data validation on the form that states that either both values must be blank or both must be not-blank. So I cannot have that one field is blank while the other is not blank.

    Do I really have to specify the exact same data validation rule on both fields/controls?

    Thanks.

    --
    eliasen

    eliasen, representing himself and not the company he works for.
    Microsoft BizTalk MVP
    Blog: http://blogs.eliasen.dk/technical/
  • 06-28-2011 07:08 AM In reply to

    Re: Data Validation on multiple fields

    In InfoPath 2010 you can copy rules (including validation rules) between fields, but in other versions, yes that's basically what you need to do.  Shouldn't take more than about 2 minutes though, should it?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-28-2011 07:33 AM In reply to

    • eliasen
    • Top 500 Contributor
      Male
    • Joined on 10-07-2010
    • Aalborg, Denmark
    • Posts 33

    Re: Data Validation on multiple fields

    Right. Rookie mistake... should've told you that I use InfoPath 2007.

    Anyways, no it won't take long. It just bugs me that now if the rule changes I need to remember to change it in two places. And of course, should a third or fourth field come into play, things get nasty :)

    Thanks for the quick reply.

    --
    eliasen, BizTalk MVP - NOT InfoPath MVP! :-)

    eliasen, representing himself and not the company he works for.
    Microsoft BizTalk MVP
    Blog: http://blogs.eliasen.dk/technical/
  • 06-28-2011 10:20 AM In reply to

    Re: Data Validation on multiple fields

    I typically advise against using code when it's not absolutely necessary, but if your validation logic does get convoluted and needs to involve many fields, I have demonstrated a way to alleviate this using code:

    http://www.infopathdev.com/forums/p/19504/67770.aspx#67770

    But I want to stress that this will only be worth your time if you are already comfortable code and having code in your form won't cause any deployment problems.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-28-2011 10:51 PM In reply to

    Re: Data Validation on multiple fields

    Hi eliasen, I'm not sure if this would fit your requirement; however to control in one place instead of two places, I would set as follows: 

    1) Assuming we have FieldA and FieldB. set Data Validation on FieldB by

    2) adding validation "FieldB needs input when FieldA is not blank" with condition
           FieldB is blank and
           FieldA is not blank

    3) and add one more validation "FieldB should be blank when FieldA is blank" with condition
           FieldB is not blank and
     
         FieldA is blank

    Then, we get validation error for FieldB with red * mark (for FieldA is non-blank and FieldB is blank), or red dotted link border (for FieldA is blank and FieldB is non-blank), and data validation is controlled in one place.

    FieldA does not get validation error with this style, but I think users can fix the issue with given validation message. This does not work if users really need error message both on FieldA and FieldB, but  just as a potential way you may consider....

    Another style would be : hide submit button if the condition is not satisfied. also condition should be clearly written in the form, but it seems still tricky... 

    thank you!

  • 06-28-2011 11:25 PM In reply to

    • eliasen
    • Top 500 Contributor
      Male
    • Joined on 10-07-2010
    • Aalborg, Denmark
    • Posts 33

    Re: Data Validation on multiple fields

    Hi, and thanks for the link.

    I am comfortable writing code and use it a lot in our current forms. However, for this form, right now I have just set the validation condition on both fields and that seems fine for now.

    Thanks.

    eliasen, representing himself and not the company he works for.
    Microsoft BizTalk MVP
    Blog: http://blogs.eliasen.dk/technical/
  • 06-28-2011 11:26 PM In reply to

    • eliasen
    • Top 500 Contributor
      Male
    • Joined on 10-07-2010
    • Aalborg, Denmark
    • Posts 33

    Re: Data Validation on multiple fields

    Hi, and thanks for your suggestions.

    I have chosen to just have the same validation condition on both fields for now.

     

    eliasen, representing himself and not the company he works for.
    Microsoft BizTalk MVP
    Blog: http://blogs.eliasen.dk/technical/
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.