B4J Question Inhibit exit from Textfield

Teech

Member
Licensed User
Longtime User
I need to inhibit lost focus from some TextFields when text property isn't a valid value.
Using FocusChanged Event I could not do it.

I can't use TextChanged Event because the control of text property is at the end of typing.

I attach an example where i'd like to remain on tf1 when tf1.Text="NO"

Have you got some suggest?
Thanks
 

Attachments

  • FocusChanged.zip
    16.6 KB · Views: 189

Erel

B4X founder
Staff member
Licensed User
Longtime User
Do you want the focus to remain on tf1 until the input is valid?

Full code:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private tf1 As TextField
   Private tf2 As TextField
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   tf1.Id="1"
   tf2.Id="2"
End Sub

Sub tf1_FocusChanged (HasFocus As Boolean)
   If HasFocus = False Then
       If tf1.Text.ToUpperCase="NO" Then
           Sleep(100)
           tf1.RequestFocus
       End If
   End If
End Sub

There is a warning message in debug mode. Ignore it.

I don't think that it is a good idea to change the focus. It can be very annoying for the user.
Different approach: https://www.b4x.com/android/forum/t...latform-views-and-dialogs.100836/#post-633557
 
Upvote 0
Top