Cond. checkboxes on one view to change another - InfoPath Dev
in

InfoPath Dev

Cond. checkboxes on one view to change another

Last post 11-02-2005 12:24 PM by jeankap. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 10-27-2005 08:16 AM

    Cond. checkboxes on one view to change another

    I'm wondering if someone has done this before:

    Use checkbox values and conditional tests on "View A" to dynamically add repeating table rows to "View B".

    I know this can't be done with validation rules on the checkboxes themselves.

    Based on what I've been reading here, and over on the Microsoft InfoPath discussions, I think this may be possible if I were to do the conditional testing on the actual button that changes views - but I'm thinking that this will cause a real performance problem as I have multiple views with checkboxes that need to populate a repeating table that makes up the last view in the form.

    Would "mirroring" the checkbox results in a hidden section on the last view be a viable approach? Would this cause any kind of severe performance hit?

    Or would it be better to generate some sort of external XML file that could be used as a secondary data source brought back in to generate that last view? I'm not wild about this second idea because the form is supposed to work in a one file, easy to move between users workflow.

    I have 8 views worth of potentially hundreds of checkboxes (which are being added conditionally as optional sections based on other checkboxes hierarchically down to 7-9 levels in some cases), so performance is one of my bigger concerns right now.

    I'm open to any suggestions/ideas/code snippets that may be helpful here.

    Thanks in advance for your thoughts.

    -Jean K.
  • 10-27-2005 09:43 AM In reply to

    Re: Cond. checkboxes on one view to change another

    If I understand what you are asking, you want to have the user check a box in View A, and when they do, an extra row is added to a table in View B. When they clear the check box, the row is deleted.

    If that is accurate, then you should be using the OnAfterChange event handler for the check box. If the value is TRUE then you would use code to insert the row. If it is FALSE you would use code to remove the row.

    To add a row, you would A) create a new row node, or B) clone an existing row node and clear any values in it, and then append it to the end or insert it somewhere in the middle of the table node.

    To remove the row, you would select it and use removeChild().

    If you are not familiar with this kind of coding, I would suggest doing a search for "cloneNode" "appendChild", "insertBefore", and "removeChild". There are plenty of online tutorials for these.

    Greg Collins [InfoPath MVP]
    InfoPath Dev
  • 10-27-2005 09:58 AM In reply to

    Re: Cond. checkboxes on one view to change another

    Thank you thank you thank you for responding!!! Many people in my organization will be very pleased if I can pull this off by Monday, so please pardon my seeming panic... ;)

    I get the fact that I need to use the OnAfterChange event in view A... I also get the fact that I'll need to append stuff to the table using the events you mention below. What remains unclear to me at this point is how to get the code I write in View A to actually create/remove the nodes in View B.

    Specifically, do I even need to "switch" views to create/remove the nodes in View B based on the checkbox values in View A? Where would I hang the actual "switch" then, since I can't put it on the onAfterChange event...

    Or, have I just totally entered the world of the DOM/XPATH and need to handle this by manipulating the XML behind the scenes rather than worrying about the views?

    quote:
    Originally posted by Greg Collins

    If I understand what you are asking, you want to have the user check a box in View A, and when they do, an extra row is added to a table in View B. When they clear the check box, the row is deleted.

    If that is accurate, then you should be using the OnAfterChange event handler for the check box. If the value is TRUE then you would use code to insert the row. If it is FALSE you would use code to remove the row.

    To add a row, you would A) create a new row node, or B) clone an existing row node and clear any values in it, and then append it to the end or insert it somewhere in the middle of the table node.

    To remove the row, you would select it and use removeChild().

    If you are not familiar with this kind of coding, I would suggest doing a search for "cloneNode" "appendChild", "insertBefore", and "removeChild". There are plenty of online tutorials for these.

    Greg Collins [InfoPath MVP]
    InfoPath Dev

  • 10-27-2005 10:10 AM In reply to

    Re: Cond. checkboxes on one view to change another

    Hi,

    You don't need to switch View. As Greg explained, you are going to manipulate the main DOM by code. If you append a child in a repeating section, it is View independent. It will be reflected when you go to the View where a control is bound to that repeating section.

    Now, to manipulate your DOM, start there:

    IXMLDOMDocument2 templateDom = (IXMLDOMDocument2)thisXDocument.CreateDOM();
    templateDom.validateOnParse = false;
    templateDom.load("template.xml");
    templateDom.setProperty("SelectionNamespaces", "xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-10-10T17-59-19'");
    IXMLDOMNode oTemplateGrp = templateDom.selectSingleNode("/my:myFields/my:group1/my:group2");
    IXMLDOMNode oTemplateNode = oTemplateGrp.cloneNode(true);
    IXMLDOMNode oGroup1 = thisXDocument.DOM.selectSingleNode("/my:myFields/my:group1");
    oGroup1.appendChild(oTemplateNode);

    Of course, you need to update the namespace with yours.

    Hope that it helps.

    Regards,

    Franck Dauché
  • 10-27-2005 10:20 AM In reply to

    Re: Cond. checkboxes on one view to change another

    Thank you! Now - just so I don't go bumbling around in my already way too slow design mode, can you please confirm exactly where I'm supposed hang this code? On the onAfterChange event for each checkbox?

    If I understand both of you this means that I can actually do this without turning it in to a huge Visual Studio project? Way cool...

    Thanks again.

    Jean K.
  • 10-27-2005 10:58 AM In reply to

    Re: Cond. checkboxes on one view to change another

    This goes in the OnAfterChange event of your checkbox on View A. This is of course for the case when e.NewValue = "true" (checkbox was checked).

    Regards,

    Franck Dauché
  • 10-27-2005 11:35 AM In reply to

    Re: Cond. checkboxes on one view to change another

    Cool. Thanks!
  • 10-27-2005 12:38 PM In reply to

    Re: Cond. checkboxes on one view to change another

    You are welcome.

    Good luck with your developments.

    Regards,

    Franck Dauché
  • 10-28-2005 11:03 AM In reply to

    Re: Cond. checkboxes on one view to change another

    Sounds like you are well on your way! Hope you were able to get it working!

    Greg Collins [InfoPath MVP]
    InfoPath Dev
  • 11-02-2005 11:33 AM In reply to

    Re: Cond. checkboxes on one view to change another

    Got another question for you guys... Which would be the better UI for implementing the code - the MSE or Visual Studio?

    I get that you get all the Visual Studio tools if you work from that interface, but what I don't know is if there's any downside to working there.

    I have many MANY checkboxes. Is one UI over the other going to help me get this done more quickly?

    Thanks again for your advice!

    Jean K.
  • 11-02-2005 12:07 PM In reply to

    Re: Cond. checkboxes on one view to change another

    Hi Jean,

    I would go with Managed Code. The initial release of IP had MSE only, SP1 introduced Managed Code. In the next version of InfoPath, MS is providing full support for System.XML. MS will eventually move away from scripting. Can't go wrong with C# or VB.Net...


    Regards,

    Franck Dauché
  • 11-02-2005 12:24 PM In reply to

    Re: Cond. checkboxes on one view to change another

    Thanks again. I'll do the import before I start adding any further code, then.
Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.