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

How to set field format based on the field Name

Participant ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

Hi All,

 

I am trying to automate the fillable field formating based on the field name, is it possible to set the field format based on the field format, I tried below script however it seems nothing changed and not showing any error.  However if i am not using the arr and use one field name it works. 

Any help much appreciated.

 

var arr = ['clm_bdate','di_date','ee_end_date_occ','ee_start_date_occ','ft_date','pt_date',' bdate_youngest', 'injury_date'];//date field names
for (var i = 0; i < this.numFields; i++) {
var A = this.getField(this.getNthFieldName(i));
if (arr.indexOf(A) >= 0) {
var cFormat = "mm/dd/yyyy";
A.setAction("Format", "AFDate_FormatEx(\""+cFormat+"\")");
A.setAction("Keystroke", "AFDate_KeystrokeEx(\""+cFormat+"\")");
}
}
this.getField("A").userName="Enter the Date in MM/DD/YYYY Format";

TOPICS
JavaScript , PDF , PDF forms

Views

139

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 2 Correct answers

Community Expert , May 02, 2024 May 02, 2024

Use the name of the field:

if (arr.indexOf(A.name) >= 0) {

Votes

Translate

Translate
Community Expert , May 02, 2024 May 02, 2024

That's because A is not a field name. It's a variable that points to a Field object.

So it needs to be:

A.userName="Enter the Date in MM/DD/YYYY Format";

Also, you have to move that line up so it's inside the for-loop where A is defined.

Votes

Translate

Translate
Community Expert ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

Use the name of the field:

if (arr.indexOf(A.name) >= 0) {

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
Participant ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

Wow. That worked Bernd, Thank you so much,  Also the tooltip (userName) not getting update on the date field.

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 ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

That's because A is not a field name. It's a variable that points to a Field object.

So it needs to be:

A.userName="Enter the Date in MM/DD/YYYY Format";

Also, you have to move that line up so it's inside the for-loop where A is defined.

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
Participant ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

LATEST

Thank you so much try67 it worked fine. 

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