Copy link to clipboard
Copied
Is there an attribute for edittext objects that limits the amount of digits I can write? I've tried "characters", "maxsize" and "maxlength", but thats not working. I know I could use a onChange function to delete characters exceeding my limit, but isn't there an attribute to prevent it beforehand?
I have Input fields for seconds & fps and want to reduce the propabillity of user-errors :
Unfortunately, not.
The `characters` parameter simply sets the horizontal size of the EditText element but does not limit the string length inside it.
Your best bet here would be to use `onChanging` attribute to trim exceeding characters.
Cheers.
Copy link to clipboard
Copied
Unfortunately, not.
The `characters` parameter simply sets the horizontal size of the EditText element but does not limit the string length inside it.
Your best bet here would be to use `onChanging` attribute to trim exceeding characters.
Cheers.
Copy link to clipboard
Copied
If anyone else has this problem, here is how I solved it with onChanging, as Tomas suggested. Simple but useful:
myEditText.onChanging = function(){limitCharacters(this,2);}
function limitCharacters(myInput,myLimit){
myInput.text = myInput.text.substr(0,myLimit);
}
Copy link to clipboard
Copied
hi @Corvinus Corax, thanks for sharing, i have question, i tried your script, it worked, but it didn't stop user from inputing character? is just make my edittext print last 2 character that i input?
Copy link to clipboard
Copied
Just wrote a quick test to confirm, and yes, you are right. The field accepts the first input as first digit, then the second as second and the third as first again, fourth as second and so on...
I think the fastest way to prevent a user to input more than those first two characters would be to lock the editfield after 2 characters are entered. That would#Ve been no suitable option for me, as I wanted my system editable at all times, but it would stop the user from inputing more than 2 chars as you suggested.
So youd' have to count in a onChangeFunction and if it reaches 2 set the enabled flag for the edittext to false.
Hope that helps with your specific problem.