Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Share variables between inputs in input_group #74

Open
fehtemam opened this issue Apr 19, 2021 · 5 comments
Open

[feature request] Share variables between inputs in input_group #74

fehtemam opened this issue Apr 19, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@fehtemam
Copy link

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'.

@wang0618
Copy link
Member

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 wang0618 added the enhancement New feature or request label Apr 19, 2021
@fehtemam
Copy link
Author

Thanks for fast response! And for the workaround!

@wang0618
Copy link
Member

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

@errorcode7
Copy link

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

@wang0618
Copy link
Member

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants