Form Checklistbox

Hi
Is it possible to create a check list with the layout of a lisbox

my code:
ui.checklist(name=‘columnsavailable’, label=‘Choices’,
choices=[ui.choice(name=x, label=x) for x in
q.client.allcolumns]),

image

Hi @rmfjd78,

yes, this is possible, try the following code using ui.inline:

from h2o_wave import Q, ui, main, app

@app('/')
async def serve(q: Q):
    q.page['form'] = ui.form_card(box='1 1 5 5', items=[
        ui.inline([
            ui.checkbox(name='checkbox1', label='Checkbox 1'),
            ui.checkbox(name='checkbox2', label='Checkbox 2'),
        ]),
        ui.inline([
            ui.checkbox(name='checkbox3', label='Checkbox 3'),
            ui.checkbox(name='checkbox4', label='Checkbox 4'),
        ])
    ])
    await q.page.save()

Result:

Hi
i’ve created the checkboxes like you said, but the name of the check box is the name of a column in a dataframe, the creation works fine, but then how can i acess this object since the name is dynamic

My creation code:
async def CreateItems(q: Q, inicio: int, tamanho: int):
items = []
fim = inicio + 5
if (fim > tamanho):
fim = tamanho
for x in range(inicio, fim):
items.append(ui.checkbox(name=‘chk’ + q.client.allcolumns[x], label=q.client.allcolumns[x]))
if (fim == tamanho):
fim = tamanho + 1
return items, fim

itemsaux = [ui.buttons([ui.button(name='plotcorrelation', label='Correlaton', primary=True),
							ui.button(name='emptyval', label='Nulls'),]),
				ui.slider(name='sliderplots', label='Total registos a visualizar : ', min=0,
						  max=len(q.client.dataframe), step=5, value=0),]

	while (inicio <= len(q.client.allcolumns)):
		checkboxilst, inicio = await CreateItems(q, inicio, len(q.client.allcolumns))
		itemsaux.append(ui.inline(checkboxilst))

	q.page['info'] = ui.form_card( box='info',
								   items=itemsaux)

My acess code:
def getselectedcols(q: Q):
indice = 0
selectedcolumns = []
while indice <= len(q.client.allcolumns):
objectname = ‘chk’ + q.client.allcolumns[indice]
if q.client.objectname.value == True:
selectedcolumns.append(q.client.allcolumns[indice])

return selectedcolumns

Accessing the objects is done via indices - q.page['form'].items[0].checkbox.... I believe you are asking about listening on the checkbox check event. Something similar to what you have should work:

for col in q.client.allcolumns:
    objectname = ‘chk’ + col
    if objectname in q.args:
        val = q.args[objectname]

To do that the checkboxes must have the trigger value equal to True?

Not necessarily. Trigger would run the handling code above on every checkbox change. If you however want to submit them all at once, don’t specify trigger and the code will run on button submission.