[Web][SithasoDaisy2]: Mashy Teaches TailwindCSS using b4x (with eBook)

Mashiane

Expert
Licensed User
Longtime User
 

Mashiane

Expert
Licensed User
Longtime User

Mashiane

Expert
Licensed User
Longtime User
Cascading Selects on the Property Bag

B4X:
Private Sub BuildPage
dettagliorigo.AddPropertySelect("pizza", "pizza", "", "", True, "left", mapPIZZA) 'how to get the change?
dettagliorigo.AddPropertySelect("size", "Size", "", "Size", True, "", CreateMap()) ' NO size ELEMENT INTO MAP (combo element)
End Sub

When the pizza changes, feed the size select with different items.

One can do this on the show method and with a change event.

On the change event, one uses the _ChangePropertyBag event. This returns a map of all the property bag properties.

The methods to update / read a property bag value starts with SetProperty??? or GetProperty???

SetPropertySelectMap - will update a select based on key value pairs
SetPropertySelectMap1 - will update a select based on key value pairs with an options to add --Nothing Selected-- blank option.
SetPropertyItemsListSort - will update a select based on a list that will be sorted. The list will be made a map with the values of the list as key value pairs
SetPropertyItemsOptions / SetPropertySelectOptions - will update a select based on delimited string. The delimited string should be like a|b|c|d|e
SetPropertyItemsList - will update a select based on a list. The list will be made a map with values of the list as key value pairs


Clearing a property bag select.

SetPropertySelectClear(?)

Adding an item to a property bag select

SetPropertySelectAddItem(?, ?, ?)

Set a property bag value

SetPropertyValue(?, ?)

Get a property bag value

a = GetPropertyValue(?)

Solution

B4X:
dim spizza as string = pb.GetPropertyValue("pizza")
select case spizza
case "a"
    dim sizem as map = createmap("s":"Small", "m":"Medium")
    pb.SetPropertySelectMap("size", sizem)
case "b"
...
case "c"
...
end Select
'change the size to be medium
pb.SetPropertyValue("size", "m")
 

Mashiane

Expert
Licensed User
Longtime User
Dear Anele, I am not able to get an item click event in SDUIDrawer's Menu. I used additem and additemchild. When I click the child item it gives string of parent id of the child not it's own id. Can you help me in this. Project could not uploaded here.

'Static code module
Sub Process_Globals
Public app As SDUIApp 'ignore
Public BANano As BANano 'ignore
'Private SQLite As BANanoSQLiteE
Private strModule As String = "Purchase"
Private appdrawer As SDUIDrawer
Public dbname As String
End Sub
Sub Initialize
dbname = "FormDB.db"
'initialize the app
BANano.Await(app.AddApp(Me, Main.AppName))
'set the font of the app
app.Font = "font-sans"
'load the base layout
BANano.LoadLayout(app.Here, "baselayout")
'add any other page not added to the drawer menu
'AddPages
AddDrawerMenu
'show the sign in page
IsAuthenticated(False)
pgSignin.Show(app)

End Sub
'show/hide drawer
Sub IsAuthenticated(b As Boolean)
' If b Then
' appdrawer.Show
' appdrawer.AdjustClippedLeft(True)
' appnavbar.Show
' appfooter.Show
' Else
' appdrawer.AdjustClippedLeft(False)
' appdrawer.Hide
' appnavbar.hide
' appfooter.Hide
' End If
End Sub
private Sub AddDrawerMenu
' SQL query
Dim strSQL As String = "SELECT caption,mindex,nindex,REPLACE(NIndex, ',', '_') AS nnindx,formcode,nformcode,MenuCategory FROM NewMenu2004 WHERE (user1 = 'admin' AND ErpModule = '" & strModule & "' AND CompanyCode = 'PPL') AND LEFT(nindex, 2) <> '00' AND mindex NOT LIKE ',%' AND nindex NOT LIKE ',%' ORDER BY nindex"
Dim rsMSMenu As BANanoSQLiteE
rsMSMenu.Initialize("FormDB", "", "", "")
'rsMSMenu.SetConnection(Main.ServerName, Main.Uname, Main.Pwd, Main.FormDB)
rsMSMenu.Execute(strSQL)
rsMSMenu.JSON = BANano.CallInlinePHPWait(rsMSMenu.MethodName, rsMSMenu.Build)
rsMSMenu.FromJSON

appdrawer.Clear("")

For Each resmap As Map In rsMSMenu.result
Dim strNindex As String = resmap.Get("nindex")
Dim strMenuName As String = resmap.Get("caption")
Dim strFormCode As String = resmap.Get("formcode")

Log(strFormCode)

' Generate Parent-Child structure
Dim result() As String = GenerateParentChild(strNindex)
Log($"Input: ${strNindex}, Parent: ${result(0)}, Child: ${result(1)}"$)

If strNindex.Trim.Length = 2 Then
Dim aditem As SDUIDrawer
aditem.Initialize(Me, "", "")
aditem = appdrawer.AddItem(result(1), strMenuName)
aditem.Tag = result(1) ' Set the menu item key as the tag

Else
appdrawer.AddItemChild(result(0), result(1), strFormCode & "-" & strMenuName)
End If
Next
End Sub
Sub GenerateParentChild(inputString As String) As String()
Dim segments() As String = Regex.Split(",", inputString)
Dim parent As String = ""
Dim child As String = ""

' Create the child
child = "F" & segments(0)
For i = 1 To segments.Length - 1
child = child & "_" & segments(i)
Next

' Create the parent
If segments.Length = 1 Then
parent = "-"
Else
parent = "F" & segments(0)
For i = 1 To segments.Length - 2
parent = parent & "_" & segments(i)
Next
End If

' Return as an array
Return Array As String(parent, child)
End Sub
Private Sub appdrawer_menu_Click (item As String)
Log(item)
End Sub
 

Attachments

  • ClickResult.png
    ClickResult.png
    21.2 KB · Views: 22
  • ParentID_and_ID.png
    ParentID_and_ID.png
    56.2 KB · Views: 25
  • queryresult.png
    queryresult.png
    237.5 KB · Views: 24
  • menu.png
    menu.png
    41.1 KB · Views: 21

Mashiane

Expert
Licensed User
Longtime User
Dear Anele, I am not able to get an item click event in SDUIDrawer's Menu. I used additem and additemchild. When I click the child item it gives string of parent id of the child not it's own id. Can you help me in this. Project could not uploaded here.

'Static code module
Sub Process_Globals
Public app As SDUIApp 'ignore
Public BANano As BANano 'ignore
'Private SQLite As BANanoSQLiteE
Private strModule As String = "Purchase"
Private appdrawer As SDUIDrawer
Public dbname As String
End Sub
Sub Initialize
dbname = "FormDB.db"
'initialize the app
BANano.Await(app.AddApp(Me, Main.AppName))
'set the font of the app
app.Font = "font-sans"
'load the base layout
BANano.LoadLayout(app.Here, "baselayout")
'add any other page not added to the drawer menu
'AddPages
AddDrawerMenu
'show the sign in page
IsAuthenticated(False)
pgSignin.Show(app)

End Sub
'show/hide drawer
Sub IsAuthenticated(b As Boolean)
' If b Then
' appdrawer.Show
' appdrawer.AdjustClippedLeft(True)
' appnavbar.Show
' appfooter.Show
' Else
' appdrawer.AdjustClippedLeft(False)
' appdrawer.Hide
' appnavbar.hide
' appfooter.Hide
' End If
End Sub
private Sub AddDrawerMenu
' SQL query
Dim strSQL As String = "SELECT caption,mindex,nindex,REPLACE(NIndex, ',', '_') AS nnindx,formcode,nformcode,MenuCategory FROM NewMenu2004 WHERE (user1 = 'admin' AND ErpModule = '" & strModule & "' AND CompanyCode = 'PPL') AND LEFT(nindex, 2) <> '00' AND mindex NOT LIKE ',%' AND nindex NOT LIKE ',%' ORDER BY nindex"
Dim rsMSMenu As BANanoSQLiteE
rsMSMenu.Initialize("FormDB", "", "", "")
'rsMSMenu.SetConnection(Main.ServerName, Main.Uname, Main.Pwd, Main.FormDB)
rsMSMenu.Execute(strSQL)
rsMSMenu.JSON = BANano.CallInlinePHPWait(rsMSMenu.MethodName, rsMSMenu.Build)
rsMSMenu.FromJSON

appdrawer.Clear("")

For Each resmap As Map In rsMSMenu.result
Dim strNindex As String = resmap.Get("nindex")
Dim strMenuName As String = resmap.Get("caption")
Dim strFormCode As String = resmap.Get("formcode")

Log(strFormCode)

' Generate Parent-Child structure
Dim result() As String = GenerateParentChild(strNindex)
Log($"Input: ${strNindex}, Parent: ${result(0)}, Child: ${result(1)}"$)

If strNindex.Trim.Length = 2 Then
Dim aditem As SDUIDrawer
aditem.Initialize(Me, "", "")
aditem = appdrawer.AddItem(result(1), strMenuName)
aditem.Tag = result(1) ' Set the menu item key as the tag

Else
appdrawer.AddItemChild(result(0), result(1), strFormCode & "-" & strMenuName)
End If
Next
End Sub
Sub GenerateParentChild(inputString As String) As String()
Dim segments() As String = Regex.Split(",", inputString)
Dim parent As String = ""
Dim child As String = ""

' Create the child
child = "F" & segments(0)
For i = 1 To segments.Length - 1
child = child & "_" & segments(i)
Next

' Create the parent
If segments.Length = 1 Then
parent = "-"
Else
parent = "F" & segments(0)
For i = 1 To segments.Length - 2
parent = parent & "_" & segments(i)
Next
End If

' Return as an array
Return Array As String(parent, child)
End Sub
Private Sub appdrawer_menu_Click (item As String)
Log(item)
End Sub
I kindly request that you do not post on existing threads. As communicated to you via email there is a question and answer thread for SithasoDaisy and this is definitely not it.

With that said, each element you add must not have an underscore in the key. It won't work. Please see the examples in the demo of adding items to the menu.

Please also enclose your code inside a code fragment to make it readable.
 

Mashiane

Expert
Licensed User
Longtime User
Dim aditem As SDUIDrawer
aditem.Initialize(Me, "", "")
aditem = appdrawer.AddItem(result(1), strMenuName)
aditem.Tag = result(1) ' Set the menu item key as the tag
1. You cannot create aditem as SDUIDrawer for each item you need to add to an existing appdrawer.

2. HTML element IDs CANNOT start with numeric values. This is an internet requirement.

3. The key for each item in the drawer cannot have an underscore as internally it uses an underscore.
 
I kindly request that you do not post on existing threads. As communicated to you via email there is a question and answer thread for SithasoDaisy and this is definitely not it.

With that said, each element you add must not have an underscore in the key. It won't work. Please see the examples in the demo of adding items to the menu.

Please also enclose your code inside a code fragment to make it readable.
Dear Anele, Thank you for your response. this underscore only within database as values not used in declaration of variables here and corrected query i sent herewith and i use this code in pgIndex.bas and as a stranger i don't know BANanoSQLiteE connection with formdb please help me


'Static code module
Sub Process_Globals
Public app As SDUIApp 'ignore
Public BANano As BANano 'ignore
'Private SQLite As BANanoSQLiteE
Private strModule As String = "Purchase"
Private appdrawer As SDUIDrawer
Public dbname As String
End Sub

Sub Initialize
dbname = "FormDB.db"
'initialize the app
BANano.Await(app.AddApp(Me, Main.AppName))
'set the font of the app
app.Font = "font-sans"
'load the base layout
BANano.LoadLayout(app.Here, "baselayout")
'add any other page not added to the drawer menu
'AddPages
AddDrawerMenu
'show the sign in page
IsAuthenticated(False)
pgSignin.Show(app)

End Sub

'show/hide drawer
Sub IsAuthenticated(b As Boolean)

End Sub

Private Sub AddDrawerMenu
' SQL query
Dim strSQL As String = "SELECT caption, mindex, nindex,REPLACE(nindex, ',', '_') AS nnindx,formcode, nformcode, MenuCategory FROM NewMenu2004 WHERE user1 = 'admin' AND ErpModule = 'Purchase' AND CompanyCode = 'PPL' AND SUBSTR(nindex, 1, 2) <> '00' AND mindex NOT LIKE ',%' AND nindex NOT LIKE ',%' ORDER BY nindex;"
Dim rsMSMenu As BANanoSQLiteE
rsMSMenu.Initialize("FormDB", "", "", "")
'rsMSMenu.SetConnection(Main.ServerName, Main.Uname, Main.Pwd, Main.FormDB)
rsMSMenu.Execute(strSQL)
rsMSMenu.JSON = BANano.CallInlinePHPWait(rsMSMenu.MethodName, rsMSMenu.Build)
rsMSMenu.FromJSON

appdrawer.Clear("")

For Each resmap As Map In rsMSMenu.result
Dim strNindex As String = resmap.Get("nindex")
Dim strMenuName As String = resmap.Get("caption")
Dim strFormCode As String = resmap.Get("formcode")

Log(strFormCode)

' Generate Parent-Child structure
Dim result() As String = GenerateParentChild(strNindex)
Log($"Input: ${strNindex}, Parent: ${result(0)}, Child: ${result(1)}"$)

If strNindex.Trim.Length = 2 Then
Dim aditem As SDUIDrawer
aditem.Initialize(Me, "", "")
aditem = appdrawer.AddItem(result(1), strMenuName)
aditem.Tag = result(1) ' Set the menu item key as the tag

Else
appdrawer.AddItemChild(result(0), result(1), strFormCode & "-" & strMenuName)
End If
Next
End Sub

Sub GenerateParentChild(inputString As String) As String()
Dim segments() As String = Regex.Split(",", inputString)
Dim parent As String = ""
Dim child As String = ""

' Create the child
child = "F" & segments(0)
For i = 1 To segments.Length - 1
child = child & "_" & segments(i)
Next

' Create the parent
If segments.Length = 1 Then
parent = "-"
Else
parent = "F" & segments(0)
For i = 1 To segments.Length - 2
parent = parent & "_" & segments(i)
Next
End If

' Return as an array
Return Array As String(parent, child)
End Sub

Private Sub appdrawer_menu_Click (item As String)
Log(item)
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
Dear Anele, Thank you for your response. this underscore only within database as values not used in declaration of variables here and corrected query i sent herewith and i use this code in pgIndex.bas and as a stranger i don't know BANanoSQLiteE connection with formdb please help me


'Static code module
Sub Process_Globals
Public app As SDUIApp 'ignore
Public BANano As BANano 'ignore
'Private SQLite As BANanoSQLiteE
Private strModule As String = "Purchase"
Private appdrawer As SDUIDrawer
Public dbname As String
End Sub

Sub Initialize
dbname = "FormDB.db"
'initialize the app
BANano.Await(app.AddApp(Me, Main.AppName))
'set the font of the app
app.Font = "font-sans"
'load the base layout
BANano.LoadLayout(app.Here, "baselayout")
'add any other page not added to the drawer menu
'AddPages
AddDrawerMenu
'show the sign in page
IsAuthenticated(False)
pgSignin.Show(app)

End Sub

'show/hide drawer
Sub IsAuthenticated(b As Boolean)

End Sub

Private Sub AddDrawerMenu
' SQL query
Dim strSQL As String = "SELECT caption, mindex, nindex,REPLACE(nindex, ',', '_') AS nnindx,formcode, nformcode, MenuCategory FROM NewMenu2004 WHERE user1 = 'admin' AND ErpModule = 'Purchase' AND CompanyCode = 'PPL' AND SUBSTR(nindex, 1, 2) <> '00' AND mindex NOT LIKE ',%' AND nindex NOT LIKE ',%' ORDER BY nindex;"
Dim rsMSMenu As BANanoSQLiteE
rsMSMenu.Initialize("FormDB", "", "", "")
'rsMSMenu.SetConnection(Main.ServerName, Main.Uname, Main.Pwd, Main.FormDB)
rsMSMenu.Execute(strSQL)
rsMSMenu.JSON = BANano.CallInlinePHPWait(rsMSMenu.MethodName, rsMSMenu.Build)
rsMSMenu.FromJSON

appdrawer.Clear("")

For Each resmap As Map In rsMSMenu.result
Dim strNindex As String = resmap.Get("nindex")
Dim strMenuName As String = resmap.Get("caption")
Dim strFormCode As String = resmap.Get("formcode")

Log(strFormCode)

' Generate Parent-Child structure
Dim result() As String = GenerateParentChild(strNindex)
Log($"Input: ${strNindex}, Parent: ${result(0)}, Child: ${result(1)}"$)

If strNindex.Trim.Length = 2 Then
Dim aditem As SDUIDrawer
aditem.Initialize(Me, "", "")
aditem = appdrawer.AddItem(result(1), strMenuName)
aditem.Tag = result(1) ' Set the menu item key as the tag

Else
appdrawer.AddItemChild(result(0), result(1), strFormCode & "-" & strMenuName)
End If
Next
End Sub

Sub GenerateParentChild(inputString As String) As String()
Dim segments() As String = Regex.Split(",", inputString)
Dim parent As String = ""
Dim child As String = ""

' Create the child
child = "F" & segments(0)
For i = 1 To segments.Length - 1
child = child & "_" & segments(i)
Next

' Create the parent
If segments.Length = 1 Then
parent = "-"
Else
parent = "F" & segments(0)
For i = 1 To segments.Length - 2
parent = parent & "_" & segments(i)
Next
End If

' Return as an array
Return Array As String(parent, child)
End Sub

Private Sub appdrawer_menu_Click (item As String)
Log(item)
End Sub
Please start a new thread with your question. You were not supposed to post questions on existing threads. zip your project from the ide by clicking the 'gift' icon and include the zip. If its large save it on Google drive and post a shareable link.

Please log and save the result of rsMSMenu in a text file and include it with your project so that I use that to reproduce your problem.

Remember the first variable for additem or addchilditem cannot start with a numeric value, cannot have an underscore, cannot have a comma but should be an alphanumeric word. This is because this creates an html element using the key you specify.
 

Mashiane

Expert
Licensed User
Longtime User
Please start a new thread with your question. You were not supposed to post questions on existing threads. zip your project from the ide by clicking the 'gift' icon and include the zip. If its large save it on Google drive and post a shareable link.

Please log and save the result of rsMSMenu in a text file and include it with your project so that I use that to reproduce your problem.

Remember the first variable for additem or addchilditem cannot start with a numeric value, cannot have an underscore, cannot have a comma but should be an alphanumeric word. This is because this creates an html element using the key you specify.
The simplest form of adding child items to the menu is this...

1739610734823.png


B4X:
private Sub AddDrawerMenu
    appdrawer.AddItem("anywhere", "Anywhere Software")
    appdrawer.AddItemChild("anywhere", "b4a", "Basic 4 Android")
    appdrawer.AddItemChild("anywhere", "b4i", "Basic 4 iPhone")
    appdrawer.AddItemChild("anywhere", "b4j", "Basic 4 Java")
    appdrawer.AddItemChild("anywhere", "b4r", "Basic 4 Arduino")
End Sub

and the click event

B4X:
Private Sub appdrawer_menu_Click (item As String)
    app.ShowToastSuccess(item)
End Sub

Will give you, b4a, b4i, b4j etc.

There are only 2 levels deep with the menu as its not a tree view. If you need tree view like functionality, use the treeview component.

By the way... when posting code, wrap it inside a code block like this

1739610856899.png

I am including a demo project here.
 

Attachments

  • BananoMin.zip
    37.9 KB · Views: 13

Mashiane

Expert
Licensed User
Longtime User
dear Anele, can you help me from Bananomssqle result set can be create columns and setitems in SUDItable please help me
Like I requested before with your previous question that you posted on this thread. Please start a new thread for your question. This thread is not for asking questions. Please start a new thread just like I explained in the email I send you when you got SithasoDaisy. Please.
 
Top