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

Viewed 303

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?

2 Answers

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

It is normal operation while typing text without space, enter, punctuation mark. After finishing typing, text over max limit would be cut.

During editing mode (a.k.a preedit mode, probably, with underline) it can not use max limit, because of handling some cases.

e.g. max length: 2 If an user wants to input "私の", the user needs to input "watashino" or "わたしの" on preedit mode. Not possible to limit text length as 2 when preedit mode.

Related