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

Script that applies f.setAction to text fields with specific names using some type of wildcard

New Here ,
Mar 19, 2024 Mar 19, 2024

Copy link to clipboard

Copied

Want to be able to look for different text fields in the document and make changes to the text fields that have a certain text in their name. 

Document has 50 text fields, but I am looking of the ones that are called HoursRow, followed by a number, so HoursRow1 HoursRow2  (total of 15 HourRow)etc 

Is there a way to put in some type of wildcard in results of getting all the text fields. Because I want to be able to change the color and format with the script for ONLY HourRow text fields

This did NOT work

for (var i = 0; i < this.numFields; i++) {
    var fname = this.getNthFieldName(i);
    var f = this.getField(fname);

    // Check if the field value contains "HoursRow"
    if (f.type === "text" && /HoursRow/.test(fname.value)) {
        // Apply your actions only to fields containing "HoursRow" in their value
        f.setAction("Format", "AFNumber_Format(2, 0, 0, 0, \"\", true);");
        f.setAction("Keystroke", "AFNumber_Keystroke(2, 0, 0, 0, \"\", true);");
        f.fillColor = color.red;
    }
}

 

If I put in code below it changes ALL text fields which I do not want to do 

for ( var i=0; i < this.numFields; i++) {
    var fname = this.getNthFieldName(i);
    var f = this.getField(fname);
    if ( f.type == "text" ) f.setAction("Format", "AFNumber_Format(2, 0, 0, 0, \"\", true);");
    f.setAction("Keystroke", "AFNumber_Keystroke(2, 0, 0, 0, \"\", true);");
f.fillColor = color.red; }

 On the same line, is it possible to change range of  text field name, same example

HoursRow1 HoursRow2 etc to only Hours1 Hours2 etc 

Thanks

TOPICS
JavaScript , PDF forms

Views

105

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 , Mar 19, 2024 Mar 19, 2024

Change this part: fname.value to f.name

You can't change field names with a script, you can only use a script to remove old fields and create new fields in their place with new names.

Votes

Translate

Translate
Community Expert ,
Mar 19, 2024 Mar 19, 2024

Copy link to clipboard

Copied

Change this part: fname.value to f.name

You can't change field names with a script, you can only use a script to remove old fields and create new fields in their place with new names.

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
New Here ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

LATEST

Ugh! But horray, it wouks! 

Thank you !!!!!

 

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