jscript to update background color in repeating table - InfoPath Dev
in

InfoPath Dev

jscript to update background color in repeating table

Last post 08-14-2007 12:42 PM by Kathryn Bates. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 08-09-2007 01:12 PM

    jscript to update background color in repeating table

    I currently have an InfoPath 2003 form that pulls in data from a secondary data source through the use of a list box.  The form is set up so that the form user can select items from the list box by hitting a button for each selection.  As each selection is made there is a repeating table on the form that gets populated programmatically row by row.  I have this part mostly working fine.  However, I am missing the ability to add some conditional formatting.  Based on the list box values, I want to change the background color of each row in the repeating table as they are added programmatically. Each different choice could have a different color that is associated with it and the desired resulting table may end up with many colors.

     

    Below is the current jscript code for the button that is working minus the background color formatting. 

     

    function CTRL5_5::OnClick(eventObj) {

     

                // each tine the button is selected a new row is added to the repeating table for the         principle selected.  The text is updated to match the text from the drop down.

     

                var parent = XDocument.DOM.selectSingleNode("/my:myFields/my:group4");

                var rowOne = parent.selectSingleNode("./my:group5");

                var rowClone = rowOne.cloneNode(true);

     

                var f9 = rowClone.selectSingleNode("my:principleSelected");

                var principleVal = eventObj.Source.selectSingleNode("//my:principlesLB").text;

     

                // The text is updated to match the text from the drop down

                f9.text = principleVal parent.appendChild(rowClone);

     

                // the starting sample row is removed

                var ss = rowOne.text.substr(4, 6);

                if (ss == "Sample") {  

                            parent.removeChild(rowOne);

                }

    }

     

    If anyone knows how or if I can add the ability to add some conditional formatting for background color based on the list box value selection, it would be very helpful.

    Thanks.

  • 08-10-2007 06:28 AM In reply to

    Re: jscript to update background color in repeating table

    I am not sure with code but you can just use the conditional formating in InfoPath on the repeating table.  Set up your conditions either based on values or related to your list box values.  Why do you need to use code when the built in functionality is available?
  • 08-10-2007 07:23 AM In reply to

    Re: jscript to update background color in repeating table

    Hi Clay,  Thank you for your response. 

    I do have my fields in the repeating table set up with conditional formatting.  The conditional formatting is set up to change color depending upon what the user has chosen form the list box.  The problem (which I may not be evident from what I wrote before) ends up being that it changes all of the rows in the table each time a selection from the list box is made. I want to retain the color formatting in each row as the rows are added to the repeating table.

    For example, say the list box has the values 1, 2 and 3. And the repeating table fields have conditional formatting based on each of the values - if the user chooses 1 the color is blue, if the user choose 2 is is yellow and if the user chooses 3 it is green.  The user selects from '1' from the list box, a new row entry is inserted into the repeating table and it is given a blue color based the selected value from the listbox.  The user selects 2 from the listbox next and another row entry is inserted into the repeating table and it is given a yellow color based the selected value from the listbox, but the row entry from the first selection also becomes yellow too.  I want the first entry to retain the blue color and was hoping to find a way to do that.  I didn't see a clear way to do it, so I thought prehaps it could be done programmatically. Do you know if it is possible to do what I described or not?

  • 08-13-2007 07:34 AM In reply to

    Re: jscript to update background color in repeating table

    I think your issue is where you are looking for your formatting.

    You currently have your conditional format looking at the list box, really you want it to look at each row to decide the color.  Hopefully the key peice of data is in each row in your repeating table, if not you would need to add it because then each row will color correctly.

    So list box would have x,y,z,a,b

    Your repeating rows would have the x,y,z,a,b column in it and it would look to the row field for the color logic.

    Hope this helps.

     

  • 08-14-2007 12:42 PM In reply to

    Re: jscript to update background color in repeating table

    Clay, You were right about my needing to have a key piece of data in each row for completing the formatting process.  While I needed the formatting information to come from the list box originally, I needed to find a way to retain the the color that was used for each item in the list box also.  I ended up adding an extra field to the repeating table to hold the key piece of data regarding the color formatting.  I made the field hidden and then I set the value of it in the jscript code based on the selection choice the user makes from the listbox.  By doing it that way, the next time a selection is made from the list box it only updates the current row being added and none of the rows that were added previously. As a result any row that was added before is able to retain the previous formatting because the value of the new hidden field does not change. 

    By the way, originally when I asked the question I wasn't sure if there was a way to read color formatting information in to a variable in my jscript code or not.  Just as I can read in text contained in a control, I thought there might be something available to read in what color formatting that was used.  If you do know of a way to do that, I would update my code to do it that way, but at least for now I have something working.  Thanks again, I appreciate all of your help!

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