3 Replies Latest reply on Sep 17, 2017 10:32 PM by MinusZero

    Dynamic Table on form

    davidg9418355 Level 1

      I am trying to design a Form with a dynamic table but want to prevent the user from adding a row if there are null values in the current row

       

      Any ideas?

        • 1. Re: Dynamic Table on form
          MinusZero Level 1

          I am assuming you are already well versed with creating a dynamic table.

           

          The simplest and easiest way to understand it is basically to create an event that interrupts the process of adding a new row. It tests the existing fields and acts based on what it finds.

           

          In your add row button, test if the rawValue is null (empty) for each object in the row. The double ampersand (&&) is logic that will only return a true value if ALL logic tests are true. If just one cell has something in it, the if statement fails and the button will create a new row.

           

          If all cells are empty, the code ends using the end; code. Nothing continues after this

           

           

          form1.#subform[0].Button1::click - (JavaScript, client)
          if(Table1.Row1.TextField1.rawValue == null && Table1.Row1.TextField2.rawValue == null && Table1.Row1.TextField3.rawValue == null && Table1.Row1.TextField4.rawValue == null && Table1.Row1.TextField5.rawValue == null )
          {
          end;
          }

          else
          {
          this.resolveNode('Table1._Row1').addInstance(1);
          if (xfa.host.version < 8) {
          xfa.form.recalculate(1);
          }
          }

           

          NOTE: This code is only correct for the very first row. As long as the first row has something in it, rows will be created. The code doesnt handle the second instance, third instance and so on. For that, you need to modify the code to handle other instances and add a new if statement for every row you want to have.

           

          Table1.Row1[0].TextField1.rawValue == null  //first row

          Table1.Row1[1].TextField1.rawValue == null  //second row

          Table1.Row1[2].TextField1.rawValue == null  //third row

           

          etc, etc

           

          There is probably another way to handle this, but if you limit the rows you can limit the repeated code. It might not be elegant, but it works and is easy to understand.

          • 2. Re: Dynamic Table on form
            davidg9418355 Level 1

            Hi

            Thanks for your information.

            I'm not able to get the code to look at the first row when I put in the following code.  The button won't work which means it won't add the second row. 

            If I remove the [0] it works fine but I need the [0] etc to look at the different rows.  Any ideas?

             

            if(Table1.Row1[0].Fullweight.rawValue == null && Table1.Row1[0].Emptyweight.rawValue == null)
            {xfa.host.messageBox("Please check the Full & Empty Weight Values.")
            end;
            }

            else
            {
            this.resolveNode('Table1._Row1').addInstance(1);
            if (xfa.host.version < 8) {
            xfa.form.recalculate(1);
            }
            }

             

             

            • 3. Re: Dynamic Table on form
              MinusZero Level 1

              Hi,

               

              I tried to get it to work but wasn't able able to.

               

              However, I can tell you that if you want to reference other instances, you need to add this.resolveNode to your table refs. I just make a habit of doing it everywhere.

               

              eg: if(this.resolveNode("Table1.Row1[0].Fullweight").rawValue == null && (this.resolveNode("Table1.Row1[0].Emptyweight").rawValue == null)

               

              When i tried the code, the messagebox kept coming up as a row was added. You will need a way to refer to a specific instance like by using .instanceIndex or .instanceManager.count etc. You could even use a variable to count the added instances in your button click code and use that.

               

              I find it handy when debugging to have a message box or textbox that shows hidden information. eg, make your textbox say [0], [1] etc so you know which instance is showing the messagebox until you get the code right.