Logic to blank controls - InfoPath Dev
in

InfoPath Dev

Logic to blank controls

Last post 04-19-2006 10:30 PM by Patrick Halstead. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 04-17-2006 01:12 PM

    Logic to blank controls

    I am looking for a way to make sure the value of a control is blank if the control gets hidden. Based on what I have seen so far, if you hide a control, for example a textbox, and you have already typed something in it, when the control gets hidden, the value is still there. I have a lot of conditional logic in the form I am working on, and when the user selects certain options, I need to ensure that the fields that get hidden as a result have their values set to zero.

    Here's what I am trying to do basically:

    1) Check the value of a field.
    2) If the value of the field is "New", then show Textbox A and Textbox B and make sure Textbox C and Textbox D are blank.
    3) If the value of the field is "Upgrade", do the opposite of 2.

    So I want to be able to do the following with code:

    1) show and hide controls based on the value of a field.
    2) set the value of a field, based on the value of another field.

    I know it can be done with rules and conditional formatting, but I'd rather do it in code if I can.

    My biggest problem here is I am not sure how to reference objects on the form within jscript, nor do I know how to reference fields to check their values. I prefer to do as little as possible with rules, etc, and do almost all of this in code. I don't see any really clear cut examples of this anywhere (I am very new to Infopath, so I may be missing it completely).

    Is there an efficient way to do these operations in code? I am making the assumption that if a rule can do it or if conditional formatting can do it, it can be done in code. If so can someone please provide an example (I will be using jscript) or point me to some that are out there.

    Thanks,
    Ryan
  • 04-17-2006 03:14 PM In reply to

    Re: Logic to blank controls

    This should be relatively easy to do in code. It sounds like you need to put code in the OnAfterChange events of the textboxes. To do this, double-click the node from the Data Source task pane and change to the Data Validation tab. At the bottom select OnAfterchange and then click Edit Code...

    Besides this, do you have any code that you have started on that we can debug? We can't write the whole thing for you!
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 04-17-2006 04:06 PM In reply to

    Re: Logic to blank controls

    Matt,
    Sorry, I am really not trying to ask for an e-handout. I am just trying to get an idea of what's required. You've given me enough information to get me started - thanks.

    Ryan
  • 04-19-2006 10:30 PM In reply to

    Re: Logic to blank controls

    Hi Ryan,
    My suggestion would be to not do this in code but use rules. Office 2007 will have a cool logic inspector tool that will make navigating rules easier (chief complaint today is they are hard to debug).
    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.