B4J Question TextChanged Event - When?

RichardN

Well-Known Member
Licensed User
Longtime User
Button A programaticly formats the text in a TextArea. The user will then press Button B to perform another operation that depends on the TextArea.Text being correctly formatted.

Button B is enabled at the successful end of the Button A click event. If the text format is changed (caught with the TextChanged event) Button B enabled = False.

Unfortunately doing this Button B is never enabled. I guess the TextChanged event is only fired when the view loses focus. I tried using a boolean flag as well as using the CallSubDelayed method but with no joy.

What is the correct method for doing this?
 

Daestrum

Expert
Licensed User
Longtime User
Small example
B4X:
Sub Process_Globals
 Private fx As JFX
 Private MainForm As Form
 Dim tf As TextField
 Dim b1, b2 As Button
 Dim flag As Boolean = False
End Sub
Sub AppStart (Form1 As Form, Args() As String)
 MainForm = Form1
 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
 MainForm.Show
 tf.Initialize("tf")
 b1.Initialize("b1")
 b1.Text = "b1"
 b2.Initialize("b2")
 b2.Text = "b2"
 b2.Enabled = False
 MainForm.RootPane.AddNode(tf,10,10,120,30)
 MainForm.RootPane.AddNode(b1,10,50,100,20)
 MainForm.RootPane.AddNode(b2,10,80,100,20)
End Sub
Sub tf_TextChanged (Old As String, New As String)
 If flag = True Then b2.Enabled = True
End Sub
Sub b1_Click
 Log("format text in tf")
 flag = True
 tf.Text = tf.Text.ToUpperCase
 b1.Enabled=False
End Sub
Sub b2_Click
 Log("TextArea now reads : "&tf.text)
End Sub
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Hi @Daestrum, thanks for the reply but it does not answer my question.

The TextChanged event is fired by both manual edit and programmatic edit. I want Button2 to be enabled after Button1_Click successfully completes, but if the user intervenes and edits the text then Button2 should be disabled again. Because TextChanged appears to fire AFTER the completion of Button1_Click I can't arrive at a logic to set Button2.Enabled = True/False as required.
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
After much thought I concluded that the use of two buttons, progressively enabled was not a good idea.

As is impossible to determine if the TextArea_TextChanged event has been fired due to it's contents being modified by code or by user input I have gone down an altogether different treatment of the problem.
 
Upvote 0
Top