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

Character limitation in few linked fields

New Here ,
Dec 11, 2024 Dec 11, 2024

Copy link to clipboard

Copied

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();
}

 

TOPICS
JavaScript , PDF , PDF forms

Views

163

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
1 ACCEPTED SOLUTION
Community Expert ,
Dec 11, 2024 Dec 11, 2024

Copy link to clipboard

Copied

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();

View solution in original post

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 ,
Dec 11, 2024 Dec 11, 2024

Copy link to clipboard

Copied

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.

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
New Here ,
Dec 11, 2024 Dec 11, 2024

Copy link to clipboard

Copied

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

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 ,
Dec 11, 2024 Dec 11, 2024

Copy link to clipboard

Copied

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;
}

 

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
New Here ,
Dec 11, 2024 Dec 11, 2024

Copy link to clipboard

Copied

Unfortunately code "disappear" as you said.

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

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 ,
Dec 11, 2024 Dec 11, 2024

Copy link to clipboard

Copied

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();

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
New Here ,
Dec 12, 2024 Dec 12, 2024

Copy link to clipboard

Copied

LATEST

TRY67 this version working fine, thank you very much!

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