6 Replies Latest reply on Nov 18, 2014 8:31 AM by syswizardx

    this.dirty replacement

    syswizardx

      I noticed this property is set to true on the slightest changes.

      I need a formdirty property such that it is only triggered upon changes to one of the form field values.

       

      Can I assume that if the Validate event handler was fired, an attempt was made to change a field ?

      In that manner I could update a global boolean of my own.

        • 1. Re: this.dirty replacement
          George_Johnson MVP & Adobe Community Professional

          If you only have fields that have a validate event, that should be OK. What sort of changes are occurring in your document other than the field values? How are these changes being triggered? If they're triggered by some JavaScript somewhere, at the beginning of the script you can store the current value of the dirty flag and restore it if you make changes other than to field values. If changes are somehow being made that are other than field value changes that aren't being done via JavaScript, the other thing you can do is set up a hidden field and keep track of field value changes with a custom calculation script. It will be triggered whenever any field value changes.

          • 2. Re: this.dirty replacement
            syswizardx Level 1

            Thanks George. I am changing fields from to/from readonly based on logic because some fields are required, others are not, and some are "N/A" and I wanted to be sure the users could not fill-in the "N/A" form fields.

             

            I think my dirty logic in the Calculation event just needs to be:

             

            bFormDirty = bFormDirty || (event.value != this.getField(event.target.name);

             

            where bFormDirty is a document-level variable.

            • 3. Re: this.dirty replacement
              syswizardx Level 1

              Oh no ! checkboxes do not have a Calculate event handler.

              I'll have to use "OnBlur". But wait !! I am already using it for some of the fields.....and I cannot build onto any embedded code because of the lack of a "getAction" method !!!

              Woe is me once again.

              • 4. Re: this.dirty replacement
                George_Johnson MVP & Adobe Community Professional

                That won't work. You're comparing event.value (which is something you're supposed to set in the calculation script) to a field object. If the calculation script is triggered, yo know that a field value somewhere in the form has changed. The field that triggered the script is given by event.source, and the field object that the script is attached to is given by event.target.

                 

                It could be simply:

                 

                // A field value changed, so dirty the form

                bFormDirty = true;

                 

                It's not clear to me if you want the form to be dirty if the user were to check a check box and then uncheck it, leaving the form in the same initial state. If so, it would get more complicated and you'd have to compare each field value to its initial value.

                • 5. Re: this.dirty replacement
                  George_Johnson MVP & Adobe Community Professional

                  For the calculation script, just set up a hidden text field whose only purpose is to include the script.

                  • 6. Re: this.dirty replacement
                    syswizardx Level 1

                    My bad....I forgot to add ".value".

                    Here's what happened when I attempted to use the Calculate event handler:

                    1) setAction was buggy - would not do text fields.

                    2) The Calculate event would fire even when the form field had not been changed. Almost any javascript that was invoked like setting the field to readonly would "fire" the event. Another bug.

                     

                    I am now going to attempt to use the Validate event handler. However, I have 100 fields that already have validate code....so those must be done by hand because of lack of "getAction()" method. How long is Adobe going to take to implement this ?

                     

                    My simple approach: bFormDirty or (this.event.valueAsString != this.getField(event.target.name).valueAsString);

                    This worked great for checkboxes....and should have worked for textboxes as well.