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.
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!
Copy link to clipboard
Copied
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:
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;
}