Need to show/hide fields from button click event - InfoPath Dev
in

InfoPath Dev

Need to show/hide fields from button click event

Last post 06-30-2006 10:16 AM by Greg Collins. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 06-27-2006 08:11 AM

    Need to show/hide fields from button click event

    Hello,

    I am very new to Infopath. Basically I have some fields and sections on the screen that are hidden by default. Basically when a certain button is clicked I need a couple of these fields to show up. Couldn't quite see a way to do this. I didn't seem to have direct access to the buttons click event from conditional formatting. Using the code behind, using the thisXDocument.DOM I couldn't see a way to access a fields show/hide properties. The fields I want to hide/show are text boxes and buttons.

    Thank you!
  • 06-27-2006 09:46 AM In reply to

    Re: Need to show/hide fields from button click event

    Hi BonsaiGuy and welcome to the forum!

    What you should do here is bind the conditional formatting to a boolean node in a secondary dom, and then have your button switch this node to the appropriate value to display the fields. This has been discussed several times on the forum, so please search around a little bit if you have any more questions.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-27-2006 10:39 AM In reply to

    Re: Need to show/hide fields from button click event

    quote:
    Originally posted by Matt Faus

    Hi BonsaiGuy and welcome to the forum!

    What you should do here is bind the conditional formatting to a boolean node in a secondary dom, and then have your button switch this node to the appropriate value to display the fields. This has been discussed several times on the forum, so please search around a little bit if you have any more questions.



    I don't understand that at all. Please explain?

    (I don't mean to steal the thread, but I have the same question).
  • 06-27-2006 11:03 AM In reply to

    Re: Need to show/hide fields from button click event

    Thanks Matt for the welcome. I don't understand what you mean by 'binding the conditional formatting'? Do you have any basic examples handy you can show me? I did a little bit of searching around and can't quite yet find an article that has addressed my specific issue.

    Thanks in advance for all your help!
  • 06-27-2006 11:28 AM In reply to

    Re: Need to show/hide fields from button click event

    Hi, what Matt is trying to say is this:

    1. Create a simple .xml file which has a field that you will use to decide whether a field in your Main DOM is visible or not.
    2. Create a data connection to this .xml file in your form template.
    3. Set conditional formatting on your field in your view to check whether this secondary data source (2DS) field (i.e. the one you just created and added) is a specific value (I like to use '0' as false and '1' as true -- so in my case I would say: if my 2DS field is '0', then hide my field in the view).
    4. Write some rules or code to set the value of your 2DS field based on whatever conditions you want.

    Thus, when the value of your 2DS field changes to 0, the field in your view hides. When you set the 2DS field to 1, the field in your view shows.
  • 06-27-2006 11:37 AM In reply to

    Re: Need to show/hide fields from button click event

    quote:
    Originally posted by BonsaiGuy

    Thanks Matt for the welcome. I don't understand what you mean by 'binding the conditional formatting'? Do you have any basic examples handy you can show me? I did a little bit of searching around and can't quite yet find an article that has addressed my specific issue.

    Thanks in advance for all your help!



    I think I know how you do it. I found this in InfoPath help. You can type in "hide" and it is the first help item to come up.

    "You can use conditional formatting (conditional formatting: Changing the appearance of a control, including its visibility, based on values entered into the form.) to hide or disable a control based on the value of another control on the form. For example, a text box for a driver's license number can be read-only unless the user enters an appropriate age into another control on the form.

    In design mode, select the control you want to hide or disable, and then click Conditional Formatting on the Format menu.
    In the Conditional Formatting dialog box, click Add.
    In the first box under If this condition is true, click Select a field or group.
    In the Select a Field or Group dialog box, select the field whose value will determine whether the control is hidden or disabled, and then click OK.
    Note Microsoft Office InfoPath 2003 verifies a condition by checking the value of the field (field: An element or attribute in the data source that can contain data. If the field is an element, it can contain attribute fields. Fields store the data that is entered into controls.) that is bound (bind: To connect a control to a field or group in the data source so that data entered into the control is saved. When a control is unbound, it is not connected to a field or group, and so data entered into the control will not be saved.) to the control, not the control itself.

    In the second and third boxes under If this condition is true, enter the rest of the condition, and then do one of the following:
    To disable the control, select the Read-only check box. Depending on the type of control, this check box may be labeled Don't allow users to insert or delete this control or Disable this control.
    Note To disable the controls in a section, you must disable each control in the section. Disabling the actual section only prevents users from inserting or deleting the section.

    To hide the control, select the Hide this control check box."
  • 06-28-2006 07:04 AM In reply to

    Re: Need to show/hide fields from button click event

    Thank you to all for your replies. What I ended up doing is pretty basic but it works.

    I just created a hidden text box somewhere on the screen off to the side. By default it's value is 0. When I click the button I make the value 1. The other controls on the screen hide/show depending on that value. That's it. :)
  • 06-28-2006 07:06 AM In reply to

    Re: Need to show/hide fields from button click event

    and sorry for all the type-o's.
  • 06-30-2006 10:16 AM In reply to

    Re: Need to show/hide fields from button click event

    That's great! I'm glad you got it working.

    One tip for you on this topic: You don't need to actually have a field in your view in order to change its value. You can change the value of any field in your DOM regardless of whether it appears in any view.

    Thus said, you don't need to have that text box "hidden" somwhere on the screen. You can still change or check the value at any time.
Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.