C CaptKronos Active Member Licensed User Longtime User Jun 27, 2019 #1 I have a requirement for a TextField to only accept integers. So I set: Code: Copy TextField1.KeyboardType=TextField1.TYPE_DECIMAL_PAD and to remove any typed decimal points I have the sub: Code: Copy Sub TextField1_TextChanged (OldText As String, NewText As String) If NewText.IndexOf(".")<>-1 Then TextField1.Text="" 'no idea why this line is necessary TextField1.Text=OldText End If End Sub If I don't include the line TextField1.Text="" the decimal point doesn't get removed but with that line (actually it can be setting .Text to any value as long as its not OldText) then it works as expected. It seems that the text field needs to be set to a different value before the system spots that the value should be changed back to OldText. With B4A it works as expected and the TextField1.Text="" line is not necessary. Is this expected behaviour for B4i?
I have a requirement for a TextField to only accept integers. So I set: Code: Copy TextField1.KeyboardType=TextField1.TYPE_DECIMAL_PAD and to remove any typed decimal points I have the sub: Code: Copy Sub TextField1_TextChanged (OldText As String, NewText As String) If NewText.IndexOf(".")<>-1 Then TextField1.Text="" 'no idea why this line is necessary TextField1.Text=OldText End If End Sub If I don't include the line TextField1.Text="" the decimal point doesn't get removed but with that line (actually it can be setting .Text to any value as long as its not OldText) then it works as expected. It seems that the text field needs to be set to a different value before the system spots that the value should be changed back to OldText. With B4A it works as expected and the TextField1.Text="" line is not necessary. Is this expected behaviour for B4i?
Erel B4X founder Staff member Licensed User Longtime User Jun 28, 2019 #2 Your best option is to use B4XFloatTextField and set the keyboard type to number. The TextChanged event in B4i actually happens right before the new text is actually set. You can call Sleep(0) instead of clearing the text. Upvote 0
Your best option is to use B4XFloatTextField and set the keyboard type to number. The TextChanged event in B4i actually happens right before the new text is actually set. You can call Sleep(0) instead of clearing the text.
C CaptKronos Active Member Licensed User Longtime User Jun 28, 2019 #3 Thanks. It's nice to know what's going on behind the scenes. Upvote 0