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

Conditional component visibility: Javascript #13

Open
bobslee opened this issue May 9, 2021 · 0 comments
Open

Conditional component visibility: Javascript #13

bobslee opened this issue May 9, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@bobslee
Copy link
Member

bobslee commented May 9, 2021

1. Usage examples

To get the idea, see:

2. (formio.js) Field Logic Schema

https://github.com/formio/formio.js/wiki/Field-Logic-Schema

3. Implementation suggestions

(1) Maybe useful library

https://github.com/PiotrDabkowski/Js2Py

(2) Dict to variables in scope

https://stackoverflow.com/questions/18090672/convert-dictionary-entries-into-variables-python

Also used in EXAMPLE below.

>>> from types import SimpleNamespace
>>> d = {'a': 123, 'b': 456}
>>> n = SimpleNamespace(**d)
>>> n.a
123

EXAMPLE code

class Component:

    def __init__():
        self.show = True

    def _set_show(self): 
        form_data = SimpleNamespace(**self.form)
        ...

    def load(self, parent=None, data=None, renderer=None):
            self.load_data(data)
            # NEW set_show
            self._set_show()

4. Form Builder (config)

image

@bobslee bobslee changed the title Conditional components visibility: Javascript Conditional component visibility: Javascript May 9, 2021
@bobslee bobslee added the enhancement New feature or request label May 9, 2021
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

1 participant