Using VSTA for writing custom validation - InfoPath Dev
in

InfoPath Dev

Using VSTA for writing custom validation

Last post 07-18-2009 12:34 AM by moggy. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 07-16-2009 05:09 PM

    • moggy
    • Top 150 Contributor
    • Joined on 06-22-2009
    • New Zealand
    • Posts 62

    Using VSTA for writing custom validation

    This is the first application I have done in ifo path and I need to write some custom validation. I am familiar with visual studio and I know how to create the event stubbs, but I can't find any sample code as to how to access the controls on the form.

    I want to write something along the lines of

    if checkbox1 and checkbox 2 and checkbox 3 and checkbox 4 and checkbox 5 but not checkbox 6 then

    raise error

    end if

     

    how do i refer to checkboxes on the form and their values

  • 07-17-2009 06:46 AM In reply to

    Re: Using VSTA for writing custom validation

    VSTA for that kind of problem? You have to really love pain.

  • 07-17-2009 03:25 PM In reply to

    • moggy
    • Top 150 Contributor
    • Joined on 06-22-2009
    • New Zealand
    • Posts 62

    Re: Using VSTA for writing custom validation

    well from what I undestand you can only validate up to 5 conditions per control which is not enough in this case. If there is a simpler way to do it I would prefer that.

     Looking at code samples I need a good knowledge of xPath, which is not something I have used before, so I do not understand the syntax that I need to get hold of the check box controls.

  • 07-17-2009 03:30 PM In reply to

    Re: Using VSTA for writing custom validation

    Sure, only 5 per condition, but you can stack additional conditions after that.  You can also concatenate the values of the checkboxes to a hidden field and do a comparison.  There is much you can do, but we need to know your EXACT scenario and all possible permutations of the logic?

  • 07-17-2009 04:08 PM In reply to

    Re: Using VSTA for writing custom validation

    moggy:
    Looking at code samples I need a good knowledge of xPath, which is not something I have used before, so I do not understand the syntax that I need to get hold of the check box controls.

     Try opening the Data Source taskpane, right-clicking one of the fields to which your one of your checkboxes is bound, and selecting Copy XPath.  Some aspects of XPath can be very simple as soon as you get used to it.

    But if you can get by without using code for this, I would highly recommend it.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-17-2009 06:47 PM In reply to

    • moggy
    • Top 150 Contributor
    • Joined on 06-22-2009
    • New Zealand
    • Posts 62

    Re: Using VSTA for writing custom validation

    wow, now that is a great tip thanks

  • 07-17-2009 06:52 PM In reply to

    • moggy
    • Top 150 Contributor
    • Joined on 06-22-2009
    • New Zealand
    • Posts 62

    Re: Using VSTA for writing custom validation

    warrtalon:

    Sure, only 5 per condition, but you can stack additional conditions after that.  You can also concatenate the values of the checkboxes to a hidden field and do a comparison.  There is much you can do, but we need to know your EXACT scenario and all possible permutations of the logic?

    It is a fairly simple form

    It is one table in the db for this part of the logic.

    There are roughly 7 columns in the table that are boolean (not a great db design but I am stuck with it).

    When a person adds a record, the logic is that one of these 7 columns (check boxes) has been ticked.  That is it.

    I don't want the validation in the individual events for the controls, just on the submit form.

  • 07-17-2009 08:29 PM In reply to

    Re: Using VSTA for writing custom validation

    I'm thinking that would be very easy, but I still need to know _exactly_ what you want to do.  All you said was, "when a person adds a record, the logic is that one of these 7 check boxes has been ticked."  Ok, what does that mean?  Is this a form built on the schema of a database, and you are reading/writing to the DB?  Is it based on a web service that reads/writes to the DB?  Is the DB data source your main data source or a secondary data source?

    I'm trying to figure out what people do when they fill out the form.  Are they filling out a row that has 7 boolean columns, and they should only be allowed to fill out one?  If they do one, do you want to disable the others?  Why do you want it only on the submit?  what if they mess up?  You'd rather them get an error instead of not being allowed commit the error?

  • 07-17-2009 11:47 PM In reply to

    • moggy
    • Top 150 Contributor
    • Joined on 06-22-2009
    • New Zealand
    • Posts 62

    Re: Using VSTA for writing custom validation

    There has to be at least one box checked it would be allowed to check all 7 boxes (though unlikely to happen)

    It is the main data source  and the form is built on the schema from a database and writes back to a sql server database. It does not involve a web service.

     The controls should not get disabled, I want the form to throw an error and prevent submission of the form until at least one of thse check boxes have been ticked

  • 07-18-2009 12:07 AM In reply to

    Re: Using VSTA for writing custom validation

    Super easy, I think:

    Place conditional formatting on your submit button (assuming a custom, non-code submit button on the canvas that triggers the submit to db) that has this expression:

    concat(my:Box1, my:Box2, my:Box3, my:Box4, my:Box5, my:Box6, my:Box7) = "falsefalsefalsefalsefalsefalsefalse"

    You basically create a condition that says, "The expression: concat(my:Box1, my:Box2, my:Box3, my:Box4, my:Box5, my:Box6, my:Box7) = "falsefalsefalsefalsefalsefalsefalse", then disable this control.

    This assumes your boolean fields default to "false" when not checked.  If it's something else like FALSE, False, or No, then substitute the 7 falses with 7 of whatever you need.  The concat is adding each box's value together in a string, and when all unchecked ,the string should be false 7 times.  Any time a box is checked, that value changes to true, and the button will become enabled.  If the user checks a box and then unchecks it, the condition is triggered again.

     

  • 07-18-2009 12:34 AM In reply to

    • moggy
    • Top 150 Contributor
    • Joined on 06-22-2009
    • New Zealand
    • Posts 62

    Re: Using VSTA for writing custom validation

    ah yes, that makes sense much easier than VSTA.

     thanks very much for that solution

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