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

Changing Text Field size with Javascript based on Conditions

New Here ,
May 21, 2021 May 21, 2021

Copy link to clipboard

Copied

Hi everyone,

 

I have a text field "exteriorElectricalDeficiency1" that causes a second text field "exteriorElectricalPrice1" to become hidden one the word "NOTE" or "note" is written in it. 

 

I'm trying increase the current width of the deficiency text box of '6.5748 in' to '7.2112 in' as long as the price field is hidden and back to its original size when it isn't hidden. 

Screen Shot 2021-05-21 at 3.51.02 PM.png

 

This is my current code attempting to accomplish this: 

//This hides the price field if the deficiency contains a note
if(event.value.indexOf("note") > -1 || event.value.indexOf("NOTE") > -1) {
    defNumber = event.target.name.substring(event.target.name.length - 1);
    this.getField("exteriorElectricalPrice" + defNumber).hidden = true;
    if (this.getField("exteriorElectricalPrice" + defNumber).hidden == true) {
        event.target.w = "7.2112in"; 
        //I've also tried event.target.x = "..."
    } 
} else {
    this.getField("exteriorElectricalPrice" + defNumber).hidden = false; 
    event.target.w = "6.5748in";
    //I've also tried event.target.x = "..."
}

 

This code is in the validation script of the deficiency box. 

I'm not sure if the '.x' or the '.w' should be used and I also don't know if the 'event.target' should be used.

 

Any input you guys can give would be amazing!

 

TOPICS
JavaScript , PDF forms

Views

1.7K

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 21, 2021 May 21, 2021

Copy link to clipboard

Copied

LATEST

First, read this article:

https://www.pdfscripting.com/public/PDF-Page-Coordinates.cfm#FldLocate

 

The Field size is determined by the fields "rect" property.

Here's the reference entry:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_Acro...

 

Your script has a couple of issues and there are several things you could do to improve it.

Fist, "defNumber" can't be used if it is never defined. So it needs to be moved out of the "if".  Also, the price field is used in all cases so might as well get that up front. For improvements, use a regular expression to detect the word "Note". And use the character index in the string to acquire the field number.  

 

var defNumber = event.target.name[event.target.name.length - 1];
var  priceFld = this.getField("exteriorElectricalPrice" + defNumber);
if(/note/i.test(event.value) {
   priceFld.hidden = true;
   // code to increase current field rectangle;
} else {
    priceFld.hidden = false; 
    // code to decrease current field rectangle;
}

 

 

 

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