PyWebIO icon indicating copy to clipboard operation
PyWebIO copied to clipboard

[feature request] Share variables between inputs in input_group

Open fehtemam opened this issue 3 years ago • 6 comments

Is it possible to define one of the inputs based on another input when we have multiple inputs in input_group? This requires some way of passing the output of an input in the input_group to the next input. An application of this is when we have two drop down menus for example and the options of the second drop down menu change based on what the user chooses from the first drop down menu. Something like this example:

DBs = ['DB1', 'DB2', 'DB3']
Tables = ['Table1', 'Table2', 'Table3', 'Table4']
text_info = input_group('Database and table name', [
                      select(label='Select the database of the table:', options=DBs, name='DB_name'),
                      select(label='Select the name of the table:', options=Tables, name='Table_name')
                      ])

So is there a way to bind the options of the second drop down menu above to the user selection from the first drop down? Like if the user chooses 'DB1' then the options in the second menu will be 'Table1' and 'Table2' but if the user chooses 'DB2' the options will be 'Table3' and 'Table4'.

fehtemam avatar Apr 19 '21 14:04 fehtemam

PyWebIO does not support this feature currently. I will add it in todo list.

Here is a workaround for now:

DBs = ['DB1', 'DB2']
Tables = {'DB1': ['Table1', 'Table2', ], 'DB2': ['Table3', 'Table4']}
db_name = select(label='Select the database of the table:', options=DBs)
table_name = select(label='Select the name of the table:', options=Tables[db_name])
put_text(table_name)

wang0618 avatar Apr 19 '21 14:04 wang0618

Thanks for fast response! And for the workaround!

fehtemam avatar Apr 19 '21 15:04 fehtemam

Now you can use the input_update() with the onchange callback to make dependent input.

Doc: https://pywebio.readthedocs.io/en/latest/input.html#pywebio.input.input_update Demo: http://pywebio-demos.demo.wangweimin.site/doc_demo?app=demo-input-update

wang0618 avatar Jun 19 '21 16:06 wang0618

Demo not work! the City selection not work, even though input_update chenged city

errorcode7 avatar Mar 24 '22 14:03 errorcode7

@errorcode7 the demo address now is https://pywebio-demos.pywebio.online/doc_demo?app=demo-input-update

Also, the bug you just found was fixed just now, but the demo server have some cache and still don't work

wang0618 avatar Mar 24 '22 15:03 wang0618