This issue is on Phonegap. I want to apply the maxlength on an input box. But in the input box of the email type maxlength does not work. (In the other type, such as password type or tel type works well.) Of course, it works well on the web. The issue only occurs Phonegap. Why Do you know?
My code
<input type="email" data-role="none" placeholder="ID" maxlength="20"/>
+) I found this question but did not give me an answer. And attr('maxlength','5')
is can't help me too..
EDIT
I found this question. and tasted both 4.2 version, 4.4.2 version. This issue certainly does not work only on the 4.4.2 version of the device.
SOLVED
To see the answers, I was trying to solve by using the following code:
var eInput = document.getElementById('Email-input');
var maxLength = eInput.maxLength;
eInput.onkeyup = function(e){
if( eInput.value.length > maxLength ){
eInput.value = eInput.value.substring(0, maxLength );
}
};
However, if I use this code should try more delete button of keyboard when try to erase after enter exceeds maxlength. And the answer of this bug was found in this link. The need to complete the word using spaces or focus out, than properly cleared. (The issue occurs only on some versions. - I think maybe 4.4.2 or higher..)
So I use this code:
eInput.value += ' ';
And it works Perfectly!
All code:
var eInput = document.getElementById('Email-input');
var maxLength = eInput.maxLength;
eInput.onkeyup = function(e){
if(eInput.value.length > maxLength){
eInput.value += ' ';
eInput.value = eInput.value.substring(0, maxLength);
}
};