Limit Text Input Box
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.
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;
}
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
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;
}
Copy link to clipboard
Copied
Thank you so much kglad!
Copy link to clipboard
Copied
you're welcome

