Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

custom formatting and calculations in form fields?

New Here ,
Aug 02, 2016 Aug 02, 2016

On my excel spreadsheet report I track  construction progress in linear ft from one station number to another.   Station numbers are expressed exactly like with decimal places except the decimal is replaced with  the plus sign '+'.  So if were to type inOn my excel spreadsheet report I track  construction progress in linear ft from one station number to another.   Station numbers are expressed exactly like with decimal places except the decimal is replaced with  the plus sign '+'.  So if were to type in 200 it becomes 2+00 (which means station # 200... i.e. 200ft from the starting point of 0+00)  It's really easy set this up in excel through custom formatting and doesn't effect the ability to subtract one station # from another to automatically calculate daily footages.   How would I go about learning how to set this up in acrobat form fields?  Thanks

TOPICS
Acrobat SDK and JavaScript
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 02, 2016 Aug 02, 2016

OK, you can use the following custom Format script for a text field:

// Custom Format script for text field

if (event.value) {

    event.value = util.printf("%.2f", event.value / 100).replace(".", "+");

}

This can be expressed in plain English with: If the field is not blank, divide the value by one-hundred, round the result to the nearest tenth, and replace the decimal point with a plus sign.

A format script is used to change what's displayed in the field while leaving the underlying field value unch

...
Translate
LEGEND ,
Aug 02, 2016 Aug 02, 2016

Do you mean that an entry of 200 becomes 200+00?

If not, that's not what you described when saying "Station numbers are expressed exactly like with decimal places except the decimal is replaced with  the plus sign '+'."

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2016 Aug 02, 2016

No, I'm sorry, I described that wrong.   200 would be expressed as 2+00.   

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 02, 2016 Aug 02, 2016

I think it would be good if you gave more examples. What would the following numbers get displayed as:

1.5

15

1000.6

34567

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2016 Aug 02, 2016

Yeah, I've explained poorly, let me try again.    Construction starts at 0+00.  Which is zero footage obviously.   Each linear foot away from the starting, Station #'s are expressed from right to left.   Station#  0+01 is one foot from the start.  Station 0+50 is 50ft and Station#  1+00 is 100ft  from the starting point of 0+00. 

If I wanted to express the Station# the distance of 1.5ft from the start I would write it as 0+01.5   But  It's not practical for most of my documentation purposes to worry about  inches so I don't need the ability to express stations beyond making sure that there is a '+' symbol before the last two digits, no matter how long the string is.    For instance,   I need to be able to just type in 708925 and upon enter have display 7089+25.   More than that, lets assume 7089+25 is my starting station for the day and 7099+75 is my finishing point. 

I need a separate cell that will calculate and return the difference of 1,050 expressed normally with a coma.  it's very easy in excel.  I'm just wondering if a pdf form can have that same level of functionality and how to achieve it.  

but for your examples. 

1.5 =  0+02 (because I would just round up)

15 =  0+15

1000.6 =   10+01 (because again I would just round up to an even 1,001 ft. 

34567 = 345+67  

hope that clarified better. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 02, 2016 Aug 02, 2016

OK, you can use the following custom Format script for a text field:

// Custom Format script for text field

if (event.value) {

    event.value = util.printf("%.2f", event.value / 100).replace(".", "+");

}

This can be expressed in plain English with: If the field is not blank, divide the value by one-hundred, round the result to the nearest tenth, and replace the decimal point with a plus sign.

A format script is used to change what's displayed in the field while leaving the underlying field value unchanged, so the field value can be used in normal numeric calculations.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2016 Aug 02, 2016

Wow, Thanks George!  Perfect! 

Thanks so much!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 02, 2016 Aug 02, 2016

It's not perfect, since the field with just that format script will allow non-numeric entries (e.g., "abc"), which you can fix with a custom Keystroke script so that it will behave the same as a field with a numeric formatting. If you want to add this, post again and I can show you (in a few hours) how to deal with this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2016 Aug 02, 2016

absolutely, I definitely want to add the custom Keystroke you spoke of. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 02, 2016 Aug 02, 2016

OK, I'll be able to post it in a bit. In the mean time, what version of Acrobat are you using?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2016 Aug 02, 2016

i'm using acrobat dc and I'm a little annoyed to learn that form users will have to convert images to pdf before inserting them to the document i'm creating.  I guess adobe just wants to assure minimal file sizes or something but talk about a seemingly arbitrary limitation to usefulness. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 02, 2016 Aug 02, 2016

What you need to do is create what's known as a document-level JavaScript and add a function to it, and then set up the Keystroke event of the field to call this function.

To add a document-level JavaScript, select: Tools > JavaScript

and then: Document JavaScripts (from the toolbar)

and then type in a script name (e.g., keystroke) and click the Add button

and then delete the function skeleton and add the following function:

function numeric_keystroke() {

    // Call the built-in numeric keystroke routine

    AFNumber_Keystroke(0, 1, 0, 0, "", false);

}

Close the script editor and close the Document JavaScripts window.

Then, set the custom Keystroke script for the text field to the following

// Custom Keystroke script

numeric_keystroke();

Now the field will only accept numeric entries and it will be formatted as you want.

Now it's (almost) perfect.

Regarding being able to set button icons, I don't believe there's a reason like that. It's more that Reader hasn't had the ability to convert images to PDF (which is what's needed when setting a button icon). They could of course add the necessary code, and you could even say it already exists in Reader, but they haven't yet extended it for use with setting button icons. Please submit a feature request  for this though, as it may happen some day with enough demand and urging. All I want is for Reader to be able to select from the same types as are allowed with an image field in an XFA (LiveCycle Designer) form, which is: JPEG, PNG, GIF, and TIFF

Feature Request/Bug Report Form

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2016 Aug 02, 2016
LATEST

Thank you so much for your help, George!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines