B4J Question (Solved) B4XPreferencesDialog disabled item become enable when required field is not provided

aeric

Expert
Licensed User
Longtime User
Example attached.

I disable a Text item (B4XFloatTextField) in a B4XPreferencesDialog
e.g Item 1 (set disabled)
and Item 2 is a required field.
When I don't provide value for Item 2 and click OK, the page refreshed and Item 1 is now enabled.

How do I make Item 1 not enable?
 

Attachments

  • example.zip
    7.6 KB · Views: 23
Solution
You need to implement it in the BeforeDialogDisplayed event:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private PrefDialog As PreferencesDialog
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    PrefDialog.Initialize(Root, "Edit", 300dip, 200dip)
    PrefDialog.SetEventsListener(Me, "PrefDialog")
    PrefDialog.LoadFromJson(File.ReadString(File.DirAssets, "template.json"))
    Button1_Click
End Sub

Private Sub Button1_Click
    Dim item As Map
    item.Initialize
    item.Put("Item 1", "value 1")
    item.Put("Item 2", "")
    Dim ps As Object = PrefDialog.ShowDialog(item, "OK", "CANCEL")
    Wait For (ps) Complete...

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need to implement it in the BeforeDialogDisplayed event:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private PrefDialog As PreferencesDialog
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    PrefDialog.Initialize(Root, "Edit", 300dip, 200dip)
    PrefDialog.SetEventsListener(Me, "PrefDialog")
    PrefDialog.LoadFromJson(File.ReadString(File.DirAssets, "template.json"))
    Button1_Click
End Sub

Private Sub Button1_Click
    Dim item As Map
    item.Initialize
    item.Put("Item 1", "value 1")
    item.Put("Item 2", "")
    Dim ps As Object = PrefDialog.ShowDialog(item, "OK", "CANCEL")
    Wait For (ps) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log(item.Get("Item 2"))
    End If
End Sub

Private Sub PrefDialog_BeforeDialogDisplayed (Template As Object)
    Dim ft As B4XFloatTextField = PrefDialog.CustomListView1.GetPanel(0).GetView(0).Tag ' Item 1
    ft.mBase.Enabled = False
End Sub
 
Upvote 0
Solution
Top