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

Limit Text Input Box

New Here ,
Mar 07, 2021 Mar 07, 2021

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.

579
Translate
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

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

Translate
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

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

Translate
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

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

Translate
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

Thank you so much kglad!

Translate
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
LATEST

you're welcome 

Translate
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