Generating Perspective View Components Dynamically

perspective
#1

I’m currently using Perspective as a way to go paperless by building form views that save data to the database when a user fills it out. For example, a daily maintenance form.

This works well so far, however I want the form to be customizable from the database. That way an external program or a user without access to Ignition designer can configure a database table called “form_items” whenever a form field needs to be added or removed.

I can handle all the database calls and other scripting in python easily, but I’m stuck at how to add a child component to the root programmatically.

I tried setting self.children = [...], but the field is read-only. Is there any way to add a component to the screen programmatically on startup?

0 Likes

#2

Sort of…

What you can do is make Views (ButtonView, CheckboxView, DropdownView) out of components. And you can make a View (ComponentChooserView) which contains only an Embedded View, where that Embedded View’s path is bound to a param. Then you can use a Flex Repeater with a path of ComponentChooserView where each instance receives params to define the View to use.

The really complicated part is also providing the options for each of the components; for example, if you want a dropdown, you need to pass the dropdown all of the value:label pairs you want as options.

0 Likes

#3

Thanks a lot, I got that to work!
It’s a little finicky, but it’s works well.
Appreciate the quick response :slight_smile:

0 Likes