Skip to content

Conditional component visibility: Javascript #13

@bobslee

Description

@bobslee

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions