[Mobile] Max Length of input not working

[Mobile] Max Length of input not working

  

Hi all.

I have an input in my mobile app and I set the max. length to 4. It works fine in the mobile emulator, but the (android) app in my phone allows me to insert as many numbers as I want to... Any ideas?

Thanks,

Maria

Hello Maria,

If your input is of type "number", the max length will not work.You can use javascript to try to limit, or you can use a Text Input instead, attached to a number variable, if you do not need the spin buttons. 

But in this second case, you will have other "problems" to solve, like how to popup the numeric keypad or how to prevent the user of enter anything other than digits, for example.

Cheers,
Eduardo Jauch

In the case you want to try something with JavaScript, you can use this one (must be placed after the input, in an not escaped expression or webblock)

"$('#" + myInput.id + "').on("input", function () {     
    if (this.value.length > 4)         
        this.value = this.value.slice(0,4); 
});"

Cheers,
Eduardo Jauch

Hi Eduardo,

Thanks for your fast reply. The input is of type "text". I meant "characters" instead of "numbers" in my first message. Still can't understand the difference between the web, the emulator and the mobile app behaviors.

Maria

Hello mariap,

I've being testing and searching.
It seems that limiting the character in an input text in android is MUCH more difficult than it looks like...

In this article, if you the time to try and test, you may be able to simplify and adapt the javascript code to do it... 

Cheers,
Eduardo Jauch

Well, in the end, I managed to adapt the code to limit the number of characters, and it worked in my Android mobile.

The id input parameter in the JavaScript is the input id.

It works, but it is not pretty...

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

In the case you want to try something with JavaScript, you can use this one (must be placed after the input, in an not escaped expression or webblock)

"$('#" + myInput.id + "').on("input", function () {     
    if (this.value.length > 4)         
        this.value = this.value.slice(0,4); 
});"

Cheers,
Eduardo Jauch

Hi Ed,

Do you have a sample OML for Web?


Thank you and regards,

Chris


Hi Christopher,

Sorry, nope. I did one for mobile, for testing, but don't have it anymore.

Cheers.

Eduardo Jauch wrote:

Hi Christopher,

Sorry, nope. I did one for mobile, for testing, but don't have it anymore.

Cheers.

Hi Ed,


Many Thanks and thank you to all Outsystems Developers/MVPs who've been active in the community!

Regards,

Chris


Eduardo Jauch wrote:

Well, in the end, I managed to adapt the code to limit the number of characters, and it worked in my Android mobile.

The id input parameter in the JavaScript is the input id.

It works, but it is not pretty...

Cheers,
Eduardo Jauch

Hi Eduardo.,

I tried this in my mobile application. Error is occuring KeyDownHandler in not defined. How can I rectify it?