B4J Question [BANanoVuetifyAD3] heeeeeeelp

I need help with this code when i push one button this perform one query and the result i need to add items to a combo but only have a list of items that say [object] [object]
error.jpg

B4X:
Sub Class_Globals
    Public vuetify As VuetifyApp
    Public turnos As VueComponent
    Public path As String
    Public name As String = "turnos"
    Private banano As BANano
    Private turnosform As VForm
    Private turnossteper As VStepper
    Private turnoDialog As VMsgBox
    Private Step1lbl As VLabel
    Private VBcajas As VBtn
    Private Vbmesa As VBtn
    Dim puntero As Int
    
    Private step3listaturnos As VListItem
    Private turnosDS As BananoDataSource
    Private turnoscmbsector As BananoDataSource
    Dim sectorv,subv,p_fecha,p_hora, socio, cone As String
    
    Private combosector As VComboBox
End Sub

Sub Initialize(v As VuetifyApp)
    'establish a reference to the app
    vuetify = v
    'initialize the component
    turnos.Initialize(Me, name)
    turnos.vuetify = vuetify
    path = turnos.path
    turnos.Path="/"
    
    '
    'build the page html here
    banano.LoadLayout(turnos.Here, "turnos")
    banano.LoadLayout(turnoDialog.CardText.Here,"turnosdetail")
    turnoDialog.BindState(turnos)
    turnossteper.AddItem("1","inicio",False,True,True)
    turnossteper.AddItem("2","Datos Personales",False,True,True)
    turnossteper.AddItem("3","Para Cuando",False,True,True)
    turnossteper.AddItem("4","Obtener",False,True,True)
    banano.LoadLayout(turnossteper.Item("1"), "mystep1")
    banano.LoadLayout(turnossteper.Item("2"), "mystep2")
    banano.LoadLayout(turnossteper.Item("3"), "mystep3")
    'add this route component to the app
    'bind datasource
    turnosDS.BindState(turnos)
    turnoscmbsector.BindState(turnos)
    '
    vuetify.AddRoute(turnos)
    turnossteper.UpdateValue(turnos, "1")
    puntero = 1
End Sub


Private Sub turnossteper_Change (item As Int)
    'bloquear el salto de un paso al otro por click
End Sub

Private Sub VBcajas_Click (e As BANanoEvent)
    turnoscmbsector.ClearWhere
    turnoscmbsector.AddWhere("sector","=","1")
    turnoscmbsector.SELECTWHERE
    sectorv="1"
End Sub

Private Sub Vbmesa_Click (e As BANanoEvent)
    
End Sub

Private Sub turnoDialog_Ok_Click (e As BANanoEvent) ' siguiente
    If puntero < 4 Then
        puntero = puntero +1
        turnossteper.UpdateValue(turnos,puntero)
        
    Else
        vuetify.ShowSwalToastWarning("No puede subir mas niveles", 1000)
    End If
End Sub

Private Sub turnoDialog_Cancel_click (e As BANanoEvent) 'anterior
    If puntero >1 Then
        puntero = puntero -1
        turnossteper.UpdateValue(turnos,puntero)
    Else
        vuetify.ShowSwalToastWarning("No puede descender mas niveles", 1000)
    End If
End Sub


Private Sub turnoscmbsector_SelectWhere (Success As Boolean, Response As String, Error As String, affectedRows As Int, Result As List)
    'Dim subsectores As String
    If Success Then
    combosector.Clear(turnos)
        For i = 0 To Result.Size-1
            combosector.AddItem(i,Result.Get(i))
        Next

    combosector.Refresh(turnos)

    End If
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
You forgot to explicitly specify the key-value properties for your dropdown. These are item-value (key) and item-text (value) in the property bag of your combo / autocomplete / auto-select. You need to give these the exact "keys" to use in your list of maps.

For example, you have

CreateMap("id":1, "name", "Anele")
CreateMap("id",2, "name", "Sebastian")

In the property bag, in the item-value use id and in the item-text use name. The combo will then know that it needs to display Anele and Sebastian and keep the keys 1 and 2 for those names.

NB: There is also an easier way to add items without using a loop, with .SetItems / .Reload (as long as the item-value and item-text are specified)

To learn more about the VComboBox, check out the Vuetify Docs... https://vuetifyjs.com/en/api/v-combobox/
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
OPTION 1

For this to work the item-value and item-text should be specified in the propertybag, depending on the keys you want to use from the list of maps

B4X:
Private Sub turnoscmbsector_SelectWhere (Success As Boolean, Response As String, Error As String, affectedRows As Int, Result As List)
   If Success And Response = turnoscmbsector.RESULT_SUCCESS Then
    combosector.SetItems(turnos, Result)
   else
      log(Error) 
End If
End Sub

NB: Its important to check the Response result as a Success can be true but the Response is RESULT_ERROR.

OPTION 2

In the latest version there is also this method, SetItems1/Reload1. This is useful where your SQL query was "SELECT *, and you dont want to pass the whole list of fields to the combo. Then you can use

B4X:
.SetItems(page, Result, "id", "name", True)

To only extract the id and name from the list of maps.

In this case, the item-value and item-text is MANDATORY to be id & text respectively on your combo and not your map keys to use, because the signature of the sub is.

B4X:
Sub SetItems1(C As VueComponent, items As List, keyFld As String, txtFld As String, bIncludeNone As Boolean)
    Dim flds As List = BANanoShared.ListOfMapsToOptions(items, keyFld, txtFld)
    If bIncludeNone Then
        Dim ns As Map = CreateMap("id":"", "text":"--Nothing Selected--")
        flds.InsertAt(0, ns)
    End If   
    UpdateItems(C, flds)
End Sub
 
Last edited:
Upvote 0
I think I have the last problem with this little project, it works perfectly on my computer (windows, with xampp) but when I pass it to a linux server (with lampp) in which I configure the database, when I enter from any pc it does not recognize the database
mysqlconfig.php:
<?php
const DB_HOST = 'localhost';
const DB_NAME = 'turnero_w';
const DB_USER = 'root';
const DB_PASS = '';
?>
I tried like this and putting the ip of the server where the code runs, but it doesn't connect either
 
Upvote 0

Magma

Well-Known Member
Licensed User
Longtime User
@Sebastian Barbosa at the same pc (linux server) works ?
not working at the clients (in the same network) ?
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Its always better to start a new thread for a new topic to avoid stuff being lost.

1. Have you checked with the Kitchen sink if you can connect to your DB?

1642696363474.png


You can access the kitchen sink online here?


2. Check your BANanoDataSource component, ensure that Dynamic is turned off i.e unchecked. This will ensure that your config file is used.
3. Check the browser console for errors. What is it indicating. Helping you without knowledge of the browser console error is futile (where available)
4. Check in Main > AppStart BANano.PhpHost?
 
Upvote 0
@Sebastian Barbosa at the same pc (linux server) works ?
not working at the clients (in the same network) ?
On the computer I use to develop with xampp it works without problems. pass the project directory to the linux server when entering from another pc on the same network I don't have access to the database, the site works but when I want to make a query I don't get data. It only runs completely if from my development pc I open the browser pointing to the linux server. It's like looking up the database on my computer

B4X:
BANano.PHPHost = $"${ServerIP}/${AppName}/"$

change to test the mysqlconfig.php with the linux server ip address with no results.


attached project. Sorry for the messiness but in this project I am trying to learn and be able to make this application as best as possible.
 

Attachments

  • prueba.zip
    452 KB · Views: 41
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
It is never a good solution to use 'Access-Control-Allow-Origin: *', except maybe for development as it allows everybody to make Ajax requests to your website. Maybe the real server is correctly configured and has another setting for the CORS and that one doesn't allow this hack. I believe in the future more and more browsers will just ignore this setting. My knowledge on server configuration is not sufficient to assist on its setup (that is why we outsource it to some experts ;) )

Alwaysbusy
 
Upvote 0
Top