6 Replies Latest reply on Jan 28, 2011 10:17 AM by BancLine

    Text field: Change format category from numeric to none

    BancLine

      Hi all,

       

      I have a loop to set all fields to read only.

       

        var fFc = this.numFields ;
        var FieldName = ''
        for (var s = 0; s < fFc; s++){
         FieldName = this.getNthFieldName(s)
          var fFn = this.getField(FieldName);
          if (! (FieldName == "FNIS_Print")){ // Don't set the print button to read only
            fFn.readonly = true;
          }
        }

       

      Our PDF provider sets some field's format category to numeric (decimal 2 with comma separator). The data merged into the field has already been formatted so, I would like to change those fields format category from numeric to none using the above loop.

       

      Is it do able? if so, can you provide sample?

       

      Thanks,

      Doug

        • 1. Re: Text field: Change format category from numeric to none
          try67 MVP & Adobe Community Professional

          No. A script can't change a field's format.

          1 person found this helpful
          • 2. Re: Text field: Change format category from numeric to none
            MarkWalsh Level 4

            The field method 'setAction' can change the format of a field, but it seems to have a few quirks (in my experience)

             

            fFn.setAction("Format", "")

             

             

            The change to the field doesn't seem to display until the file is closed and reopened. Plus, when you open up the field properties, it will still display the same 'Number' format (although in my case, the decimal places changed from 2 to 0), and the 'Custom format' doesn't show whatever code is set in the setAction method. As a test, I used the following code to set a field to display a text string instead of the numeric format it was set to:

             

            this.getField('Text1').setAction("Format", "event.value = 'Test value'")

             

            Upon reopening the file, the field properties still have the format set to a numeric format, but the field does display 'Test Value' as it's format.

            1 person found this helpful
            • 3. Re: Text field: Change format category from numeric to none
              BancLine Level 1

              Currently, I am manually changing the format category from currency to none and on occasion I miss one.

               

              If I loop through all the fields, is there a way to test if any are formatted as currency?

               

              We only send changes 3 times per year and if I miss any, the users have to wait 4 months before I can send a correction.

               

              Thanks

              • 4. Re: Text field: Change format category from numeric to none
                AcroBishop Level 1

                Sorry to resurrect an ancient topic, but I searched high and low for the answer to this same question.  Eventually, through my own testing I discovered an interesting solution which solves the problem mentioned here.

                 

                You can't just set the "Format" property to an empty string, you must also set the "Keystroke" property to an empty string.  This will effectively change the field format to "None" both in behavior and within the field's Format tab. i.e.

                 

                var f = this.getField('text_field')

                f.setAction('Format','')
                f.setAction('Keystroke','')

                • 5. Re: Text field: Change format category from numeric to none
                  gkaiseril MVP & Adobe Community Professional

                  One can also change a fields format from none to some other formats by calling certain application functions:

                   

                  AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
                  AFPercent_Format(nDec, sepStyle)
                  AFDate_FormatEx(cFormat)
                  AFTime_Format(ptf)
                  AFSpecial_Format(psf)

                   

                  An example for suppressing the value of a percentage field value when zero or a null string using the 'Custom validation script'. The field can either be formatted as 'None' or 'Number':

                   

                  if( (event.value == 0) | (event.value.toString() == "") ) {

                  // value is either zero or null

                  event.value = ""; // clear the display value

                  AFNumber_Format(2, 0, 0, 0, "", false); // format as number with 2 decimal places

                  } else {

                  AFPercent_Format(2, 0); // format as a percentage with 2 decimal places

                  }

                   

                  The above script will also work in Reader.

                   

                  There is also a series of "Keystroke" functions with the same parameters to set the keystroke script.

                   

                  If you are setting the action scripts for the  Keystroke and the Foramt by JavaScript, I would also set the Validate action script.

                  • 6. Re: Text field: Change format category from numeric to none
                    BancLine Level 1

                    Thanks AcroBishop.

                     

                    That worked. Now I can focus on development rather than manually changing thousands of field properties.