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

Set multiple fields to certain format

Community Beginner ,
Oct 17, 2017 Oct 17, 2017

Copy link to clipboard

Copied

I have a PDF form that's gone awry; some check boxes turn black when printing, while others don't and there's no clear reason for this. Worse is that those black check boxes are completely black regardless of whether they're checked or not, so there's no telling whether they're actually checked.

I've saved the scripts from the "All JavaScripts" option of the form, as the scripts work great, and now I want to load those into a new export (from InDesign) of the form. Unfortunately that doesn't work; none of the scripts seem to save in the new form. I'm guessing it's because they can't be bound to the proper fields due to them not having the correct formatting set yet.

All fields are named logically as in "quantity-[product]" and "net-price-[product]", so I'm thinking it should be possible to run a JavaScript once (using an action set to a button press?) to set all fields whose names start with a certain string ("net-price" for example) to a certain format. Now that brings me to my problem: I can't get the sample scripts found online to work at all.

var theField = getField(getNthFieldName(fieldNumber));

for (i = 0; i < numFields; i++) {

  if (theField.value.indexOf("net-price-") = "0") {

    theField.setAction("Format", 'AFNumber_Format(2, 2, 0, 0, "\u20ac", false)');

  }

}

Can anyone offer me some advice on this?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

660

Translate

Translate

Report

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

Community Expert , Oct 17, 2017 Oct 17, 2017

Using code you found online is often risky... The code above contains multiple errors in it.

What you want to do is possible, though. Assuming the format settings in the code above are correct, try this code:

var counter = 0;

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (/^quantity-/.test(f.name) || /^net-price-/.test(f.name)) {

        f.setAction("Format", 'AFNumber_Format(2, 2, 0, 0, "\u20ac", false)');

        counter++;

...

Votes

Translate

Translate
Community Expert ,
Oct 17, 2017 Oct 17, 2017

Copy link to clipboard

Copied

Using code you found online is often risky... The code above contains multiple errors in it.

What you want to do is possible, though. Assuming the format settings in the code above are correct, try this code:

var counter = 0;

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (/^quantity-/.test(f.name) || /^net-price-/.test(f.name)) {

        f.setAction("Format", 'AFNumber_Format(2, 2, 0, 0, "\u20ac", false)');

        counter++;

    }

}

app.alert("Done. " + counter + " fields were edited.",3);

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 17, 2017 Oct 17, 2017

Copy link to clipboard

Copied

PS. I've developed a tool that allows you to do it easily and quickly, without having to write any code:

Custom-made Adobe Scripts: Acrobat -- Apply Format to Multiple Text Fields

Votes

Translate

Translate

Report

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
Community Beginner ,
Oct 18, 2017 Oct 18, 2017

Copy link to clipboard

Copied

LATEST

Thanks, that works great!

Votes

Translate

Translate

Report

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