Text boxes in repeating sections are not populating correctly - InfoPath Dev
in

InfoPath Dev

Text boxes in repeating sections are not populating correctly

Last post 01-02-2009 06:04 PM by Alpharisk. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 01-18-2008 12:50 PM

    • DrewCH
    • Not Ranked
    • Joined on 01-18-2008
    • Posts 5

    Text boxes in repeating sections are not populating correctly

    Hi everyone,

    I'm having a problem with populating the text boxes in my repeating sections.  The repeating section has 1 textbox where the user will paste a string of text, which is then parsed and used to populate the rest of the text boxes in the section.  The code works fine for the first box.  The user can then click the 'Add Item' button, which makes another section which is identical to the first.  The problem is that when the user pastes another string on information into the new textbox, none of the fields are populated.  I'm not sure if it has something to do with the field tags, or if I'm just not coding the functionality properly; I'm kind of figuring out form programming as I go.  If anyone can shed some light on my problem, it would be much appreciated.

    Thanks in advance,

    Drew

     

    public void Input_OnAfterChange(DataDOMEvent e)

    {

    // Write your code here to restore the global state.

    if (e.IsUndoRedo)

    {

    // An undo or redo operation has occurred and the DOM is read-only.

    return;

    }

    // A field change has occurred and the DOM is writable.

    // Write your code here.

    try

    {

         IXMLDOMNode InputString = e.XDocument.DOM.lastChild.selectSingleNode("/my:myFields/my:Dealer_Info/my:Input");     if (InputString.text == "")

         {

              // do nothing

         }

         else

         {

         // specify field delimiters

         string[] seps = new string[19] {"Name:", "Branch ID:", "Status:", "Address 1:",

         "City :", "State:", "Zip:", "Time Zone:", "Start:", "End:", "Contact Name:",

         "Contact Number:", "Fax Number:", "Market:", "Email:", "User Name:",

         "Password:", "Type:", "Status:"};

         string[] elements = InputString.text.Split(seps, System.StringSplitOptions.RemoveEmptyEntries);

         if (elements.Length == 19) // correct info has been pasted into field

         {

              elements[17] = elements[17].Trim();

              if (elements[17].Equals("Master")) // populate fields

              {

                   e.XDocument.DOM.selectSingleNode(
    "/my:myFields/my:Dealer_Info/my:Dealer_Name").text = elements[0];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Branch_ID").text = elements[1];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Branch_Status").text = elements[2];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Address").text = elements[3];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:City").text = elements[4];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:State").text = elements[5];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Zip").text = elements[6];

                   elements[7] = elements[7].TrimStart(' ');

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Time_Zone").text = elements[7].Substring(0, 3);

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Start_Time").text = elements[8];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:End_Time").text = elements[9];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Contact_Name").text = elements[10];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Contact_Num").text = elements[11];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Fax_Num").text = elements[12];

                   e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Market").text = elements[13];               if (elements[14].Contains("Users"))

                  {

                       elements[14] = elements[14].Remove(elements[14].Length - 6);

                  }

                  e.XDocument.DOM.selectSingleNode(
    "/my:myFields/my:Dealer_Info/my:Email").text = elements[14];

                  e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Username").text = elements[15];

                  e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Password").text = elements[16];

                  e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Type").text = elements[17];

                  e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Status").text = elements[18];

              }

             else

             {

                  System.Windows.Forms.
    MessageBox.Show("Username is not listed as the Master user in the control system." +

                        " Please verify that you have selected the correct user.");

                  return;

              }

         }

         else

         {

              System.Windows.Forms.
    MessageBox.Show("Invalid input. Please make sure you " +               "have pasted the correct fields into the text box.");

         }

    }

    }

    finally

    {

    // implement any clean-up that needs to be done

    }

    }

  • 01-18-2008 04:26 PM In reply to

    Re: Text boxes in repeating sections are not populating correctly

    Your selections are a problem... You are always selecting from the root node down... This is bad for repeating lists. You need to select from the current row.

    BAD: IXMLDOMNode InputString = e.XDocument.DOM.lastChild.selectSingleNode("/my:myFields/my:Dealer_Info/my:Input");
    GOOD: IXMLDOMNode InputString = e.Site;

    BAD: e.XDocument.DOM.selectSingleNode("/my:myFields/my:Dealer_Info/my:Dealer_Name").text = elements[0];
    GOOD: e.Site.selectSingleNode("../my:Dealer_Name").text = elements[0];

     

  • 01-21-2008 07:37 AM In reply to

    • DrewCH
    • Not Ranked
    • Joined on 01-18-2008
    • Posts 5

    Re: Text boxes in repeating sections are not populating correctly

    I tried replacing my selections with .Site as you suggested, but the fields are still not updating;  it still fills in the text boxes for the first section correctly, but when I tried to enter information in the newly generated Input textbox in the next instance of the repeating section, nothing was filled in again.  Is there something I'm not doing correctly to specify that I want the fields in the last Repeating Section to update?  I tried using some of the properties in conjunction with .Site, but I kept getting the same results.

    try

    {

    IXMLDOMNode InputString = e.Site; //.selectSingleNode("/my:myFields/my:Dealer_Info/my:Input");

    if (InputString.text == "")

    {

    // do nothing

    }

    else

    {

    // specify field delimiters

    string[] seps = new string[19] {"Name:", "Branch ID:", "Status:", "Address 1:",

    "City :", "State:", "Zip:", "Time Zone:", "Start:", "End:", "Contact Name:",

    "Contact Number:", "Fax Number:", "Market:", "Email:", "User Name:",

    "Password:", "Type:", "Status:"};

    string[] elements = InputString.text.Split(seps, System.StringSplitOptions.RemoveEmptyEntries);

    if (elements.Length == 19) // correct info has been pasted into field

    {

    elements[17] = elements[17].Trim();

    if (elements[17].Equals("Master")) // populate fields

    {

    e.Site.selectSingleNode(
    "/my:myFields/my:Dealer_Info/my:Dealer_Name").text = elements[0];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Branch_ID").text = elements[1];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Branch_Status").text = elements[2];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Address").text = elements[3];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:City").text = elements[4];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:State").text = elements[5];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Zip").text = elements[6];

    elements[7] = elements[7].TrimStart(' ');

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Time_Zone").text = elements[7].Substring(0, 3);

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Start_Time").text = elements[8];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:End_Time").text = elements[9];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Contact_Name").text = elements[10];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Contact_Num").text = elements[11];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Fax_Num").text = elements[12];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Market").text = elements[13];if (elements[14].Contains("Users"))

    {

    elements[14] = elements[14].Remove(elements[14].Length - 6);

    }

    e.Site.selectSingleNode(
    "/my:myFields/my:Dealer_Info/my:Email").text = elements[14];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Username").text = elements[15];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Password").text = elements[16];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Type").text = elements[17];

    e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Status").text = elements[18];

    }

    else

    {

    System.Windows.Forms.
    MessageBox.Show("Username is not listed as the Master user in the control system." +

    " Please verify that you have selected the correct user.");

    return;

    }

    }

    else

    {

    System.Windows.Forms.
    MessageBox.Show("Invalid input. Please make sure you " +"have pasted the correct fields into the text box.");

    }

    }

    }

    finally

    {

    // implement any clean-up that needs to be done

    }

    }

  • 01-21-2008 08:01 AM In reply to

    • DrewCH
    • Not Ranked
    • Joined on 01-18-2008
    • Posts 5

    Re: Text boxes in repeating sections are not populating correctly

    I was just stepping through the code and saw that in the local variables, e.Operation is listed as being "Insert" the first time through. However, on the 2nd run, it changes to "Delete".  This property is read-only.  Is there and way that I can get it to register as an Inset operation the 2nd time?

  • 01-21-2008 08:13 AM In reply to

    • DrewCH
    • Not Ranked
    • Joined on 01-18-2008
    • Posts 5

    Re: Text boxes in repeating sections are not populating correctly

    Please disregard the last post.  This happened after information was pasted over information already in the field.

  • 01-21-2008 04:02 PM In reply to

    Re: Text boxes in repeating sections are not populating correctly

    You are close. It's still not working because you only made half the change. Note carefully the difference in the XPaths:

    BAD: e.Site.selectSingleNode("/my:myFields/my:Dealer_Info/my:Dealer_Name").text = elements[0];
    GOOD: e.Site.selectSingleNode("../my:Dealer_Name").text = elements[0];

    You are using ABSOLUTE XPaths (which always start at the root node and work their way down to the FIRST repeating row). You need to be using RELATIVE XPaths, which start with the CURRENT row and get sibling fields. The ".." tells the XPath to go to the parent node and start selecting from there.

  • 01-22-2008 07:02 AM In reply to

    • DrewCH
    • Not Ranked
    • Joined on 01-18-2008
    • Posts 5

    Re: Text boxes in repeating sections are not populating correctly

    Wow, I'm feeling a bit foolish.  I noticed that in your first reply but thought it was just a shorthand for the rest of the XPath.  I made the change and it's working like a charm.  Thanks again for all your help, Greg.

  • 01-22-2008 02:44 PM In reply to

    Re: Text boxes in repeating sections are not populating correctly

    No problem. Glad to help. The XPath language can be difficult at times to get your mind around.

  • 08-12-2008 10:28 AM In reply to

    Re: Text boxes in repeating sections are not populating correctly

    I just posted this inquiry to a different thread in this forum (http://www.infopathdev.com/forums/p/8156/31383.aspx#31383) but thought I'd post it here as well... 

    I am at a loss.  Is it really just my xpaths that are faulty or is it also the type of event handler I am declaring/working on?  Well, all that and faulty coding?  Let me ask, will a changed event trigger each time a new row is added to a repeating table?  Or do I need a different handler?  Morever, is the handler associated with the right grouping?  Please note that I am using the default insert row functionality that comes with the repeating table control (in other words, I am not using a button control).  That said, assuming that a changed event triggers with each new row insert, then the problem is definitely with the xpaths and/or the code.  Currently, I can auto-populate the person's job title textbox ***for the first row only***.  Once I insert another row and resolve a name from the Contact Selector, however, the person's job title textbox no longer auto-populates and so on with other inserted rows.

    This is happening in a ***browser-enabled*** form in the browser (not in preview mode). 

    Can someone please let me know how to resolve this quickly?

    My main data source for this particular set of fields looks like:

    (...)
    selector_table (repeating group)
        selector_control
           Person (repeating group)
              DisplayName
              AccountId
              AccountType
      job_title textbox
      textbox2
      textbox3
      textbox4
    (...)

    My secondary data source for GetUserProfileByName is the standard structure everyone's familiar with.

    This is what I am coding: 

    public void selector_table_Changed(object sender, XmlEventArgs e)

    {

    string id = string.Empty;

    string title = string.Empty;

    XPathNavigator secondary = DataSources["GetUserProfileByName"].CreateNavigator();

    XPathNavigator main = MainDataSource.CreateNavigator();

    id = main.SelectSingleNode("/my:myFields/my:selector_table/my:gpContactSelector/my:Person[1]/my:AccountId", NamespaceManager).Value;

    secondary.SelectSingleNode("/dfs:myFields/dfs:queryFields/s0:GetUserProfileByName/s0:AccountName", NamespaceManager).SetValue(id);

    DataSources["GetUserProfileByName"].QueryConnection.Execute();

    title = secondary.SelectSingleNode(@"/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData[s0:Name = ""Title""]/s0:Values/s0:ValueData/s0:Value", NamespaceManager).Value;

    e.Site.SelectSingleNode("/my:myFields/my:selector_table[1]/my:job_title", NamespaceManager).SetValue(title);

    }

    Thank you in advance. 

  • 01-02-2009 06:04 PM In reply to

    • Alpharisk
    • Not Ranked
    • Joined on 01-02-2009
    • Jacksonville, FL
    • Posts 1

    Re: Text boxes in repeating sections are not populating correctly

     I just wanted to add my thanks to this thread as well. I had been struggling with this problem for days. I finally found the answer I was looking for here. I had posted on Expert's Exchange and the Microsoft Office site and had no luck. My thanks again to Greg!

     Tom

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