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

How to set field format based on the field Name

Participant ,
May 02, 2024 May 02, 2024

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
587
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
2 ACCEPTED SOLUTIONS
Community Expert ,
May 02, 2024 May 02, 2024

Use the name of the field:

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

View solution in original post

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
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.

View solution in original post

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

Use the name of the field:

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

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

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

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
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.

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

Thank you so much try67 it worked fine. 

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