6 Replies Latest reply: Apr 19, 2012 4:31 AM by DKinsley RSS

    If statement, when true, runs two actions

    DKinsley Community Member

      How do I write an if statement that when true, runs two actions?

       

      if (NumericField1.rawValue > 0)

      {

          xfa.resolveNode("#pageSet.Page1.Image1").presence = "visible" + Rectangle1.presence = "visible";

      }

        • 1. Re: If statement, when true, runs two actions
          radzmar CommunityMVP

          Generally all actions should be written in a separate code line:

           

          if (NumericField1.rawValue > 0) {

              xfa.resolveNode("Image1").presence = "visible";

              xfa.resolveNode("Rectangle1").presence = "visible";

          }

          • 2. Re: If statement, when true, runs two actions
            DKinsley Community Member

            Still does not work. I must be doing something wrong. Form is linked below...

             

            https://acrobat.com/#d=M9EvNlO*0XvduxOVaoZ-Qg

            • 3. Re: If statement, when true, runs two actions
              radzmar CommunityMVP

              Try

               

              if (xfa.resolveNode("form1.#subform.#subform[1].NumericField1").value.oneOfChild.value > 0) {

                          xfa.resolveNode("form1.#subform.#subform[1].Rectangle1").presence = "visible";

              }else{

                        xfa.resolveNode("form1.#subform.#subform[1].Rectangle1").presence = "invisible";

                        }

              • 4. Re: If statement, when true, runs two actions
                DKinsley Community Member

                Two things are supposed to happen whe nthere are more than one or more attachments.

                 

                The yellow rectangle becomes visible and the "paperclip" appears at the top of the form (on master page).

                • 5. Re: If statement, when true, runs two actions
                  radzmar CommunityMVP

                  Well, the problem is you're trying to control objects on the body page and a masterpage at once.

                  This is generally not so simple to accomplish.

                   

                  I changed your form a bit.

                  The paperclip image and the numeric field now monitor the valur of the numeric field and change the wanted property if the value is larger than 0.

                   

                  Script for the paperclip (wrapped in a subform)

                  form1.Page.#subform[0].NumericField1::ready:layout - (JavaScript, client)

                   

                  this.ui.numericEdit.border.fill.color.value = this.rawValue > 0 ? "255,255,153" : "255,255,255";

                  Script for the numeric field

                  form1.#pageSet[0].Page1.Clip::ready:layout - (JavaScript, client)

                   

                  this.presence = xfa.resolveNode("Page.#subform.NumericField1").rawValue > 0 ? "visible" : "hidden";

                   

                  Script for the remove button

                  form1.Page.#subform[0].Button3::click - (JavaScript, client)

                   

                  var myDoc = event.target;

                  var sFile = ListBox1.getDisplayItem(ListBox1.selectedIndex);

                   

                  try {

                            if (sFile !== "") {

                                      var nResponse = xfa.host.messageBox("You are about to delete the highlighted attachment. \n\nDo you want to continue?", "Deleting an Attachment", 1, 2);

                                      if (nResponse == 4) {

                                                myDoc.removeDataObject(sFile) + ListBox1.deleteItem(ListBox1.selectedIndex) + (NumericField1.rawValue = NumericField1.rawValue - 1);

                                      }

                            } else {

                                      xfa.host.messageBox("No document selected.");

                            }

                  } catch (e) {

                            xfa.host.messageBox("Error in removing document");

                  }

                   

                  https://acrobat.com/#d=55A3x-8Zm7D29eK7*brqxQ

                  • 6. Re: If statement, when true, runs two actions
                    DKinsley Community Member

                    radzmar:

                     

                    Now that I see the correct answer I know I never would have figured this out. Your form works great! This is why I was trying to close the pane that contains the paperclip so users would only use this interface. Thank you so much for all your help with this. I really appreciate your time and sharing your expertise.

                     

                    Have a great day!

                    -Don