PyWebIO
PyWebIO copied to clipboard
[feature request] Share variables between inputs in input_group
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'.
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)
Thanks for fast response! And for the workaround!
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
Demo not work! the City selection not work, even though input_update chenged city
@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