15 Replies Latest reply: Jul 3, 2012 3:49 AM by ubolrat RSS

    if´s and exit event

    ubolrat Community Member

      Hello,

       

      I am working on my first form and solving problem after problem but now Im stuck.

       

      In my table I want this to happen.

       

      If TextField8 is not empty TextField1 should get red border color .

      But if TextField1 is not empty it should be black.

       

      The proble Im getting is that when I fill TextField8, TextField1 get red bordercolor and if I enter something in TextField1 it turns black.

      But If I aleady entered text in TextField1 and then fill TextField8 it still turns red till I click it.

       

      So is this problem because There is a exit event on both TextField1 and 8?

       

      I am very new to this.

        • 1. Re: if´s and exit event
          Niall O'Donovan Community Member

          Hi,

           

          I suspect that the script in the exit event of TextField8 is NOT testing to see if TextField1 is null or not.

           

          Can you post your form or provide the script that you are using in both fields?

           

          Niall

          • 2. Re: if´s and exit event
            ubolrat Community Member

            Hello,

             

            Yes I guess that can be it.

             

            I tried several different ways and the one I have now looks like this.

             

            if (xfa.event.target.name === "TextField8") {

                 if(xfa.event.target.rawValue != null && xfa.event.target.name != "")

                      var vRow = xfa.event.target.parent.index; 

                      xfa.resolveNode("Table1.Row1[" + vRow + "].TextField1").border.edge.color.value = "255,0,0";

                      }

                      else

                      {

            if (xfa.event.target.name === "TextField1") {

                 if(xfa.event.target.rawValue != null && xfa.event.target.name != "")

                      var vRow = xfa.event.target.parent.index; 

                      xfa.resolveNode("Table1.Row1[" + vRow + "].TextField1").border.edge.color.value = "0,0,0";

                      }

                     }

             

            / Thanks

            • 3. Re: if´s and exit event
              Niall O'Donovan Community Member

              Hi,

               

              You can make this a whole lot simpler. Script in one field in a repeating can easily reference another field in the same row, just be a simple relative reference. You do not need to resolve the node.

               

              I would use the following JavaScript in the exit event of BOTH TextField1 and TextField8:

               

              if (TextField1.rawValue === null && TextField8.rawValue !== null) {
                   TextField1.border.edge.color.value = "255,0,0";
              }
              else {
                   TextField1.border.edge.color.value = "0,0,0";
              }
              

               

              That should match the logic, but may need a bit of tweaking.

               

              Niall

              • 4. Re: if´s and exit event
                ubolrat Community Member

                Yes this works great.

                 

                But if I want to do this inside a table with the same thing on every row with 7 fields?

                 

                If TexField8 is not empty Fields 1-7 will get a red border if they are empty.

                • 5. Re: if´s and exit event
                  Niall O'Donovan Community Member

                  Hi,

                   

                  You would just need to extend the logic to deal with all of the objects that you need to change visually.

                   

                  For example, you could have seven if/else statements that look at the .rawValue of a praticular field and TextField8.

                   

                  Make sense?

                   

                  Niall

                  • 6. Re: if´s and exit event
                    ubolrat Community Member

                    Yes on one row understand

                     

                    But If I going to do this on all 20 rows I would need to loop this right?

                    • 7. Re: if´s and exit event
                      Niall O'Donovan Community Member

                      Yes, that is correct. If you want to have the visual appearance on the row-by-row basis, then the script above will work.

                       

                      If on the other hand, you want a user's actions on one row to affect ALL rows, then a loop of FormCalc would do the trick.

                       

                      However, without seeing the form it is difficult to give a full script. Also I would need to know the full logic for the visual changes.

                       

                      Niall

                      • 8. Re: if´s and exit event
                        ubolrat Community Member

                        Can I send you the form?

                         

                        You helped me out much with things before also and Im starting to understand thngs now

                         

                        Though it´s much copy/paste with code I reuse.

                        • 9. Re: if´s and exit event
                          Niall O'Donovan Community Member

                          Hi,

                           

                          If you upload your form to a file sharing site, like Acrobat.com; Publish it; and them post the published URL here.

                           

                          I will have a look when I can.

                           

                          Niall

                          • 10. Re: if´s and exit event
                            ubolrat Community Member

                            https://acrobat.com/#d=wydl3Z3XYS2b1-cTj3RS8A

                             

                            I want this to happen.

                             

                            If TextField8 (Reserve for breeding) is not empty the TextFields 1-7 from the left should get a red border. On that row only.

                             

                            If they are already filled or being filled the border should get black.

                             

                            This should be for all rows.

                             

                            I´m not asking you to do the work but maybe some suggestion.

                             

                            If you have time take a look but no hurry. I appreciate all your help very much.

                             

                            Thanks

                            • 11. Re: if´s and exit event
                              Niall O'Donovan Community Member

                              It will be later today!

                              • 12. Re: if´s and exit event
                                ubolrat Community Member

                                You gotten a chance to look at the form.

                                 

                                Another quick question if anyone have a solution.

                                 

                                 

                                This script almost works as I want. Though if TextField8 on one row is filled I want the loop to check that. Now if TextField8 on one row is filled all TextField10, 11,12 are read only. But if I go down one row and exit a empty TextField8 then everything gets open again. Possible to do?

                                 

                                var oRows = xfa.resolveNodes("Table1.Row1[*]");

                                if (xfa.event.target.name === "TextField8") {

                                          if (xfa.event.target.rawValue === null) {

                                                    for (var i=0; i<oRows.length; i++) {

                                                              oRows.item(i).TextField10.access = "open";

                                                              oRows.item(i).TextField11.access = "open";

                                                              oRows.item(i).TextField12.access = "open";

                                                              form1.Page1.Table1.Header.Head8.fontColor = "0,155,0";

                                                              form1.Page1.Table1.Header.Head9.fontColor = "0,155,0";

                                                              form1.Page1.Table1.Header.Head10.fontColor = "255,0,0";

                                                              form1.Page1.Table1.Header.Head11.fontColor = "65,105,225";

                                                              form1.Page1.Table1.Header.Head12.fontColor = "65,105,225";

                                                              TextField13.fontColor = "0,0,0";

                                                              TextField13.rawValue = "Mouse Forms";

                                                              TextField14.fontColor = "0,0,0";

                                                              TextField14.rawValue = "Mouse Forms";

                                                              CheckBox3.rawValue = "0";

                                                    }

                                          }

                                          else {

                                                    for (var i=0; i<oRows.length; i++) {

                                                              oRows.item(i).TextField10.access = "readOnly";

                                                              oRows.item(i).TextField11.access = "readOnly";

                                                              oRows.item(i).TextField12.access = "readOnly";

                                                              form1.Page1.Table1.Header.Head8.fontColor = "0,155,0";

                                                              form1.Page1.Table1.Header.Head9.fontColor = "0,155,0";

                                                              form1.Page1.Table1.Header.Head10.fontColor = "100,100,100";

                                                              form1.Page1.Table1.Header.Head11.fontColor = "100,100,100";

                                                              form1.Page1.Table1.Header.Head12.fontColor = "100,100,100";

                                                              TextField13.fontColor = "0,155,0";

                                                              TextField13.rawValue = "Breeding Form";

                                                              TextField14.fontColor = "0,155,0";

                                                              TextField14.rawValue = "Breeding Form";

                                                              CheckBox3.rawValue = "1";

                                                    }

                                          }

                                }

                                 

                                Guess I started a bit to difficult with this

                                • 13. Re: if´s and exit event
                                  Niall O'Donovan Community Member

                                  Hi,

                                   

                                  Here is the form back to you: https://acrobat.com/#d=DsIMPAPVPUvrnTpuFkkkDQ.

                                   

                                  I have deleted the 19 rows and just left one Row1, which is set to repeat in the Object > Binding palette. This means that you only have one row to script and it will be applied to all 20 rows.

                                   

                                  Have a look at the script in the exit event of TextField8.

                                   

                                  Hope that helps,

                                   

                                  Niall

                                  • 14. Re: if´s and exit event
                                    ubolrat Community Member

                                    Thanks.

                                     

                                    It looks like it works the same way though.

                                     

                                    If I write in TextField8 then all TextFields 10,11,12 gets readonly.

                                    But if I go down to row to and just exit it then everything gets open.

                                     

                                    If one of the TextField8 is filled then the option to use 10 11 and 12 should not be possible on this page. Then they have to add a new form and choose another column for that info.

                                     

                                    I start to feel like a pain in the XXX ask all this questions.

                                     

                                    Sorry man

                                    • 15. Re: if´s and exit event
                                      ubolrat Community Member

                                      Hey thanks

                                       

                                      I played around with yur idea and I got it to work if I write if textField8 === null && textField 8 o2 to and so on in the textField.

                                       

                                      And the same with the read only.

                                       

                                      Then it works like I want.

                                       

                                      The only strange thing now is that when I add a new instance on the next page it does not show alternative row shading. But hey, Im lucky anyway

                                       

                                      Thanks so much for your help.