B4J Code Snippet [ABMaterial] Making an ABMCombo MultiSelect with ABMCheckboxes

mauriegio

Member
Licensed User
Longtime User
no error, only don't set che checkbox .... where put the routine ABMComboSetCheckedModal ?
 

MichalK73

Well-Known Member
Licensed User
Longtime User
There is a simpler method in my opinion.
In global class define 'Private listCombo As Map'.
B4X:
'Class module
Sub Class_Globals
    Private ws As WebSocket 'ignore
    ' will hold our page information
    Public page As ABMPage
    ' page theme
    Private theme As ABMTheme
    ' to access the constants
    Private ABM As ABMaterial 'ignore   
    ' name of the page, must be the same as the class name (case sensitive!)
    Public Name As String = "home"  '<-------------------------------------------------------- IMPORTANT
    ' will hold the unique browsers window id
    Private ABMPageId As String = ""
    ' your own variables   
    Private listCombo As Map  '<------ Variable added :)
End Sub

In WebSocket_Connect inicjalize map.
Inicjalize MAP:
#Region ABM
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)   
    LogDebug("Connected")
    listCombo.Initialize   
    ws = WebSocket1       
    ....
    ...

Adding fields to a combo.
It is important that the ItemID of the combo box be the same as the ID of the checkbox.
B4X:
    Dim asel As ABMCombo
    asel.Initialize(page,"asel","Resources","650","")
    asel.AddItem("opt_"&1,"Option 1",ABMCheckBoxItem("opt_"&1,"Option 1",True))
    asel.AddItem("opt_"&2,"Option 2",ABMCheckBoxItem("opt_"&2,"Option 2",False))
    asel.AddItem("opt_"&3,"Option 3",ABMCheckBoxItem("opt_"&3,"Option 3",True))
    asel.AddItem("opt_"&4,"Option 4",ABMCheckBoxItem("opt_"&4,"Option 4",False))
    asel.AddItem("opt_"&5,"Option 5",ABMCheckBoxItem("opt_"&5,"Option 5",False))
    page.Cell(2,1).AddComponent(asel)

ABMCheckBoxItem:
Sub ABMCheckBoxItem( id As String, text As String, state As Boolean) As ABMContainer
    Dim ItemCont As ABMContainer
    ItemCont.Initialize(page, id, "")
    ItemCont.AddRowsM(1,False,0,20, "").AddCellsOSMP(1,0,0,0,12,12,12,0,0,10,10,"")
    ItemCont.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
     listCombo.Put(id,state)
    Dim chk As ABMCheckbox
    chk.Initialize(page, id,text, state,"")
    ItemCont.Cell(1,1).AddComponent(chk)
    Return ItemCont
End Sub

Now all you need is a read after selection from the combo.
B4X:
Sub asel_Clicked(itemId As String)
    Dim combo As ABMCombo = page.Component("asel")
    Dim container As ABMContainer = combo.GetComponent(itemId)
    Dim checkbox As ABMCheckbox = container.Component(itemId)
    listCombo.Put(itemId, checkbox.State)
    Dim j As JSONGenerator
    j.Initialize(listCombo)
    page.Msgbox("",j.ToPrettyString(2),"asel checked","ok",False,"","")
End Sub

No additional code is needed in JavaScript.
 

mauriegio

Member
Licensed User
Longtime User
Thank so much

MichalK73

your code work very well .... my friend !!!
best regard

Maurizio​

 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…