Skip to main content
Participant
March 7, 2021
Question

Limit Text Input Box

  • March 7, 2021
  • 1 reply
  • 714 views

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.

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    March 8, 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;
    }

    Participant
    April 21, 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

    kglad
    Community Expert
    Community Expert
    April 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;
    }