5 Replies Latest reply on Jun 5, 2012 4:42 PM by George_Johnson

    removing data from calculated field

    CustodyHelp

      Hello,

       

      I was just curious if there was a way to remove data that has been calculated, while still allowing for a user to input data into the text field.  For example a certain textbox gets populated with "Hello" if this other checkbox is checked, but then if i had an "else event.value = "";" to remove the data upon the checkbox not being checked, then this doesn't allow the user to manually enter data into that certain text box, because when it is entered, it gets removed right away, because that other checkbox is unchecked. 

       

      Any help would be great

        • 1. Re: removing data from calculated field
          George_Johnson MVP & Adobe Community Professional

          Yes, that's possible. If you post the exact code you're currently using, I can show you how the code can be revised to do what you want.

          • 2. Re: removing data from calculated field
            CustodyHelp Level 1

            Hello George,

             

            Thanks, here it is:

            --

            var s = getField("alt holidays").valueAsString;

             

            if (s == 1) {

            event.value = "Alternating Holidays";

            } else {

            event.value = "";

            }

            --

            But i would like a user to still be able to input data into this field, even when "alt holidays" is unchecked..

             

            Thanks

            • 3. Re: removing data from calculated field
              George_Johnson MVP & Adobe Community Professional

              See if the following calculation script for the text field makes it behave as you want:

               

              // Get a reference to the check box

              var f = getField("alt holidays");

               

              // If the check box change triggered this script...

              if (event.source && event.source === f) {

                 

                  // ...set this text field value and make it read-only if the check box is selected...

                  if (f.value !== "Off") {

                      event.value = "Alternating Holidays";

                      event.target.readonly = true;

                 

                  // ...otherwise clear this text field and make it editable

                  } else {

                      event.value = "";

                      event.target.readonly = false;

                  }

              }

               

               

              The text field to which this script is attached won't get cleared if its calculate event is triggered by a field value change of any field other than the check box, including the text field itself. Said another way, it is only cleared by the script at the time the check box is unchecked.

               

              The advantage to doing it this way, as opposed the using the Mouse Up event of the check box, is the script will run if the check box value is set programatically or by importing a data file.

              • 4. Re: removing data from calculated field
                CustodyHelp Level 1

                Ah.. yea worked like a charm! thanks a lot,

                 

                if you could explain to me how this if statement works that would be great..

                 

                // If the check box change triggered this script...

                if (event.source && event.source === f) {

                • 5. Re: removing data from calculated field
                  George_Johnson MVP & Adobe Community Professional

                  The event.source property identifies the field that triggered the field's calculate event. The problem is, it's not always defined, as when you're editing the field. So the first part [ if (event.source ] is there to avoid generating an error after you edit the script, which is a bit annoying when it happens.

                   

                  The second part [ if (event.source === f) ] prevents the rest of the script from executing if some field other than the check box is the field that caused the calculate script to execute. Since you don't want that part of the script to execute when the text field that it's attached to is changed, or any field other than the check box, this is what's done.