I have a TextField view designed to receive four digits that represent a year number. Whilst you can specify the keyboard type in designer or code, when deploying to a tablet you don't get a choice because the full keyboard is deployed regardless. In that case the user is able to enter unwanted alpha characters as well as digits.
In the absence of a 'Masked Edit' view I have to process the input keys in 'TextChanged' to weed out all but numerals. However, right from the outset the Sub does not perform quite as I expected.
If I equate txtYear.Text to a literal within this subroutine like txtYear.Text="Some text", the view changes immediately as expected. However if I change the value of TextField.Text OR the NewText variable conditional on the value of NewText the changes do not occur.
Surely this is a bug?
Is this Sub intended to work in some different way?
Should I be looking at a different solution to mask a 1-4 digit number?
In the absence of a 'Masked Edit' view I have to process the input keys in 'TextChanged' to weed out all but numerals. However, right from the outset the Sub does not perform quite as I expected.
B4X:
Sub txtYear_TextChanged (OldText As String, NewText As String)
End Sub
If I equate txtYear.Text to a literal within this subroutine like txtYear.Text="Some text", the view changes immediately as expected. However if I change the value of TextField.Text OR the NewText variable conditional on the value of NewText the changes do not occur.
B4X:
Sub txtYear_TextChanged (OldText As String, NewText As String)
txtYear.Text = "Some String Value" 'this line works immediately and exactly as expected
'I would expect the next line to suppress the insertion of a 5th char but it
'does not until a 6th is added when it truncates correctly to 4 chars
If NewText.Length > 4 Then txtYear.Text = NewText.SubString2(0,4)
End Sub
Surely this is a bug?
Is this Sub intended to work in some different way?
Should I be looking at a different solution to mask a 1-4 digit number?
Last edited: