Skip to main content
Inspiring
December 11, 2024
Answered

Character limitation in few linked fields

  • December 11, 2024
  • 6 replies
  • 755 views

Hi,

i know how to limit character in one filed in Acobat, but how can I limit characters to 250 in three linked fields? Fields are linked with this script:

Field 1

var t=this.getField("Fileld 2");
if (event.fieldFull) {
getField("Field 2").setFocus();
}

 

This topic has been closed for replies.
Correct answer try67

Unfortunately code "disappear" as you said.

Maybe you have another solution / some tip for this bug?


As I said, it should still work, even if it disappears.

The only solution is to place the code in a doc-level function and then call that function from the event.

So like this:

 

// Doc-level script
function validateFieldsLength() {
	var newValue = AFMergeChange(event);
	var otherText = this.getField("Field2").valueAsString;
	var maxTextLength = 100;
	if ((newValue.length + otherText.length) > maxTextLength) {
		app.alert("The combined text may not exceed " + maxTextLength + " characters.");
		event.rc = false;
	}
}

// Field-level script - Keystroke event
validateFieldsLength();

6 replies

try67
Community Expert
Community Expert
December 11, 2024

You can use a custom-made KeyStroke script to calculate the length of the text in the current field, plus the text in the other fields, and then reject the value based on the total length.

Inspiring
December 11, 2024

Thank you try67.

Can you help me with write this KeyStroke? I searched for some solutions but I'm not into JS and it's too difficult for me

try67
Community Expert
Community Expert
December 11, 2024

Here's an example. Note the code might "disappear" when you apply it (due to a bug in Acrobat), but it should still work:

 

var newValue = AFMergeChange(event);
var otherText = this.getField("Field2").valueAsString;
var maxTextLength = 100;
if ((newValue.length + otherText.length) > maxTextLength) {
	app.alert("The combined text may not exceed " + maxTextLength + " characters.");
	event.rc = false;
}