B4J Question [AB Material] Issue

Harris

Expert
Licensed User
Longtime User
Trying to create a ABMCombo to use in my Insert/Edit forms - as a lookup, populated from a DB table.
The updated table will hold the PKey to the lookup table.
Normally, the combo would have a pair of key / value.

' create combo
Dim combo1 As ABMCombo
combo1.Initialize(page, "combo1", "Select a person", 650, "")
combo1.IconName = "mdi-action-account-circle"

' add items
combo1.AddItem("combo1S1", "Mommy", BuildSimpleItem("S1", "mdi-action-account-circle", "{NBSP}{NBSP}Mom"))

The BuildSimpleItem adds a label for each item....

Here the key is "combo1S1"
Here the value is "Mommy"

How does one retrieve the key when all we have access to is the value (combo1.text)?
At a loss here, stopping my development...

When resolved, hope to turn it into a practical example.

....

I am thinking I may need to use a Map to lookup the (key/value) pair and extra
code methods to set and get the DB values...


Thanks
 

alwaysbusy

Expert
Licensed User
Longtime User
This will be changed in the next release. There were more reported issues with the combo (like when using it on a modal sheet). It is based on an input text field but needed some special attention. Text will disappear and be replaced by ActiveItemId which will set/return the item id. Also, the event 'clicked' was not activated which also returned the item id.

Will be released by the end of next week. I'm working on a feedback app to centralize things because it's hard to keep track. The source code will be released of the app and will demonstrate a lot of things (add/edit records). I'm hoping writing this will also bring out some of the issues.
 
Upvote 0

prajinpraveen

Active Member
Licensed User
Longtime User
Hello,

is there a solution to "How does one retrieve the key when all we have access to is the value (combo1.text)?"

Thank you
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Yes.

Get the page or modal sheet component.
Get the ActiveItemId of combo. This is the key you set it to, which should be unique for each item added (ie. your db ID, PK).
ActiveCaseId is a private global I used to know which item was selected from the table so I can do what is needed later.

When combo item is selected, code sets combo key.
If populated from a table, use SetActiveItemId - without having to manually set it by clicking.

B4X:
Sub mtlist1_clicked(Target As String)
    Dim mtl As ABMCombo = page.Component("mtlist1") ' fetch component
    ActiveCaseId = mtl.GetActiveItemId   ' get key selected...
    Log("target: "&Target&"  case: "&ActiveCaseId)
End Sub

https://www.b4x.com/android/forum/t...ate-a-combo-based-on-another-selection.61920/

See above post for more...
 
Upvote 0

prajinpraveen

Active Member
Licensed User
Longtime User
Thank you.
In this case, Log("target: "&Target&" case: "&ActiveCaseId) both Target and ActiveCaseId are the same.
Would it be possible to get the text that is selected? unless i am missing something.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
It used to send the text in a very early version of ABMaterial, but it had to be changed to an ID because it caused al kind of troubles (as the text could be anything, including e.g. html tags which caused problems very difficult to track). As you are the one filling the combo, you should know what each ID represents (e.g. it could be the primary key in a database table).
 
Upvote 0
Top