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

ExtendScript edittext limit number of characters

Participant ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

Is there an attribute for edittext objects that limits the amount of digits I can write? I've tried "characters", "maxsize" and "maxlength", but thats not working. I know I could use a onChange function to delete characters exceeding my limit, but isn't there an attribute to prevent it beforehand?

 

I have Input fields for seconds & fps and want to reduce the propabillity of user-errors :

Corvin0_0-1594716392677.png

 

TOPICS
How to , Scripting

Views

872

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

Advocate , Jul 14, 2020 Jul 14, 2020

Unfortunately, not.

The `characters` parameter simply sets the horizontal size of the EditText element but does not limit the string length inside it.

Your best bet here would be to use `onChanging` attribute to trim exceeding characters.

 

Cheers.

Votes

Translate

Translate
Advocate ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

Unfortunately, not.

The `characters` parameter simply sets the horizontal size of the EditText element but does not limit the string length inside it.

Your best bet here would be to use `onChanging` attribute to trim exceeding characters.

 

Cheers.

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
Participant ,
Jul 14, 2020 Jul 14, 2020

Copy link to clipboard

Copied

If anyone else has this problem, here is how I solved it with onChanging, as Tomas suggested. Simple but useful:

 

myEditText.onChanging = function(){limitCharacters(this,2);}

 

function limitCharacters(myInput,myLimit){
myInput.text = myInput.text.substr(0,myLimit);
}

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

Copy link to clipboard

Copied

hi @Corvinus Corax, thanks for sharing, i have question, i tried your script, it worked, but it didn't stop user from inputing character? is just make my edittext print last 2 character that i input?

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
Participant ,
May 27, 2022 May 27, 2022

Copy link to clipboard

Copied

LATEST

Just wrote a quick test to confirm, and yes, you are right. The field accepts the first input as first digit, then the second as second and the third as first again, fourth as second and so on...

 

I think the fastest way to prevent a user to input more than those first two characters would be to lock the editfield after 2 characters are entered. That would#Ve been no suitable option for me, as I wanted my system editable at all times, but it would stop the user from inputing more than 2 chars as you suggested.

 

So youd' have to count in a onChangeFunction and if it reaches 2 set the enabled flag for the edittext to false.

Hope that helps with your specific problem.

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