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

How to delete only one text field out of many copies using a JS

Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

If I add a field with the same name twice using the script and method

this.addField("name", …… )

then in the field collection I will have two fields named "name#0" and "name#1", which correlates with the values order property in the field collection.

Calling this.removeField("name") will unfortunately delete both fields.

Is it possible to delete only the field, e.g. "name#0", of course, using a script?

TOPICS
How to , JavaScript , PDF forms

Views

574

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

Hi,

 

I have not been able to find a method to delete the fields using JavaScript, but are you able to change how you create the fields so that you create a count of the fields, then you could create the fields as

this.addField("name." + count, .........)

This allows you to manage all the fields with

this.getField("name");

or get a specific one with

this.getField("name.1")

 

hope this helps

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

If those are the names being displayed on the field list in "Prepare Form" mode, then you don't have two fields. You have one field with two widgets.  #0 and #1 are the widget numbers.

The proper way to access a single widget of a field is with dot notation. 

 

this.getField("name.0") 

 

gets the object for "name#0".  Use can use this to set field widget parameters, such as the fill color. Widget parameters are all those that are related to the appearance of the field on the page, and have nothing to do with the field level properties, such as the field value.

 

Unfortunately this notation does not allow you to delete the specific widget using the "removeField" function. 

A work around would be to collect all the field parameters for the one you want to keep, delete the field, then recreate it. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

Of course I use the documentation. The two most important scripting manuals in Adobe are actually open all the time. However, some answers I will not find in them. The second thing, but this is my problem, but probably not only, English is not my native language, and sometimes some nuances are hard for me to understand. I belong to the generation of Poles who were forced to learn the Russian language, and English appeared only in college and in the basics. Such a digression.

As for the previous suggestion regarding a different approach to creating fields, in this case I want to have fields with exactly the same name before and after changes, because these changes can occur quite often, and as you have just made sure me, it is impossible to delete a specific widget. In addition, it is not possible to programmatically set the TAB order in detail and it is also not possible to move (without deleting) the fields between the pages of the form. So the only reasonable option is "read the properties of the old field, delete it, create a new one in the new place, give the remembered properties". And that's what I did and it works…. and then find out that for security reasons you can't add a blank page with the script ..... 😞

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 ,
Dec 16, 2022 Dec 16, 2022

Copy link to clipboard

Copied

Why do you need to add a blank page to do that?

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
Explorer ,
Dec 16, 2022 Dec 16, 2022

Copy link to clipboard

Copied

The forms I make often contain sections with repetitive data. For example, an application for a large family card, where the details of the children of this family are provided. The problem is that you don't know how many such sections will be in a given application. Usually 3-4 sometimes more, and in extreme cases more than 20 :-)…. So far, there are forms where "just in case" there is free space for 15 such sections. Of course, in 90% of cases, it is unnecessary to print 3-4 pages of an unfilled form, and in 1% it is a problem because it is not enough. Of course, it begs to make a form in which I will be able to add (and remove) another section if necessary when filling it out, thanks to which I will always print exactly as much as I need and not "just in case". Of course, such forms have different elements before and after such sections, so making page templates is virtually impossible due to the number of possible combinations. It's better to add a blank page and insert what I want and where I want with a script. Quite tedious work but only at the beginning before you do the procedures that support it. I already dealt with this blank page, I just understood how templates work and how to use them. Well, I already use them in my project 😉 just a blank page is the template. I have almost finished procedures just adding such sections and moving the rest of the elements (also with adding and deleting pages). I probably would have already done it but, no offense, the debugger in Adobe is just a nightmare…. people are supposed to go to Mars and here is something like from the Dark Middle Ages....

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 ,
Dec 16, 2022 Dec 16, 2022

Copy link to clipboard

Copied

LATEST

Rather than making page templates with all the variations, make templated page sections. Then combine the different sections by overlaying them on top of each other. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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