htmlvalidationinputtizen-web-apptizen-studio

Input field maxlength is not working for text type on Tizen Studio


I'm developing a Samsung TV web app using Tizen Studio 3.3 and I have a input field with text type. I want to set charter limit to 64 using input property maxlenght. But It's working only for number, when input alphabet char then not working.

<input type="text" placeholder="Search.." name="search" id="search-in" maxlength="64">

How to limit text in input for Tizen Studio?


Solution

  • You can do this if maxlength is not working.this is an alternative solution

    <input type="text" placeholder="Search.." name="search" id="search-in"  oninput="checkSearchLength(event)">
    

    oninput will call checkSearchLength function whenever you will type something on input field .

      function checkSearchLength(e){
            var srch = document.getElementById("search-in").value;
            if(srch.length>64){
                document.getElementById("search-in").value = srch.substring(0, 64);
                alert("Max 64 Characters are allowed");
                console.log("<--------------  are"+ srch.length+ " ------------------>")
                return;
            }else{
                console.log("<-------------- total Characers are"+ srch.length+ " ------------------>")
            }
    }
    

    this function will check the length of input and substring the value when length will be greater than 64