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

Limit Text Input Box

New Here ,
Mar 07, 2021 Mar 07, 2021

Copy link to clipboard

Copied

Evening everybody.

Small question: is there a way to limit the amount of characters you can write in the TextInput box in Adobe Animate html5 canvas component ?

Thank you for your time.

Views

373

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 ,
Mar 07, 2021 Mar 07, 2021

Copy link to clipboard

Copied

for component ti:

 

var max_chars = 2;
if(!this.alreadyExecuted) {
function keyupF(e) {
if (e.target.value.length >= max_chars) {
e.target.value = e.target.value.substr(0, max_chars);
}
}
$("#dom_overlay_container").on("keyup", "#ti", keyupF.bind(this));
this.alreadyExecuted = true;
}

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 Beginner ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

Hi kglad,

I had a similar request (max characters) but I would also like to restrict the input to numbers only. I had some luck with:

if(!this.inputNumber_change_cbk) {
function inputNumber_change(evt) {
var regex = /[^0-9]/g;
evt.target.value = evt.target.value.replace(regex, "");
}
$("#dom_overlay_container").on("change", "#timeLength", inputNumber_change.bind(this));
this.inputNumber_change_cbk = true;

}

Trouble is that it only works when the user then clicks in the other text box I have. I cannot rely on the user doing that.

Basically I need it to occur as the user types into the #timeLength field.

Can you please advise?

Regards,

Ron

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 ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

var max_chars = 2;

var regex = /[^0-9]/g;
if(!this.alreadyExecuted) {
function keyupF(e) {
e.target.value = e.target.value.replace(regex, "");
if (e.target.value.length >= max_chars) {
e.target.value = e.target.value.substr(0, max_chars);
}
}
$("#dom_overlay_container").on("keyup", "#ti", keyupF.bind(this));
this.alreadyExecuted = true;
}

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 Beginner ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

Thank you so much kglad!

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 ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

LATEST

you're welcome 

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