Dynamically alter field length based on input from another field

New Here ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

Hi,

 

I am creating a form that has an input for phone numbers. I am trying to dynamically limit the field length based on the input from another field (country). If the field is domestic, I want to limit the field to 10 characters, however, if the field is selected as other, then I want to allow up to 20 characters. Is this something that I can do through custom logic?

TOPICS
How to , JavaScript , PDF forms

Views

96

Likes

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

correct answers 1 Correct answer

Enthusiast , Apr 26, 2022 Apr 26, 2022

Here is an example for what can be done.

@+

Likes

Translate

Translate
Enthusiast ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

You can write this script in onBlur action:

if (this.getField("country").value=="domestic") event.target.charLimit=10;
else event.target.charLimit=20;

Or in custom keystroke script if you know the pattern of both phone numbers, and you place one or two regular expressions.

@+

Likes

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
Adobe Community Professional ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

This needs to be done in a different event. Limiting the number of characters after the user exited the field is like closing the gates after the cows have fled... You need to do it before-hand, preferably in an action associated with the other field ("country"), such as the Validation event, or Mouse Up (if it's a check-box).

Likes

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
Enthusiast ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Here is an example for what can be done.

@+

Likes

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 ,
Apr 27, 2022 Apr 27, 2022

Copy link to clipboard

Copied

LATEST

Thanks! That's exactly what I was looking to implement. I didn't think that it should have been in the keystroke section to limit while the user is still in the field entry rather than after they've exited

Likes

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