[IGN-6759]Is there a way to obtain the type of a component through Python Script in Perspective?

I am trying to create a python script where I will pass in the name of a component in my view and output the type of component it is. So for example I would have a Checkbox named Component1, a Dropdown named Component2 and a Button named Component3. To callout Component1 I would just use view.getChild("root").getChild("Component1"), using that code I have access to the known properties, but it is desired to be able to determine that Component1 is a Checkbox. Does this functionality exist? I have currently just resorted to adding "type" as a parameter for each component, and then manually entering the Component Type into this parameter for each component...

image

Not really easily that i know of.

I suppose you could dig for it in the view.json...

Why do you need to know the type of the components though?
Whats the goal of calling out these types?

In my script I am trying to obtain the value that was entered into the component, but in each component the properties that house this value are named slightly different. For example for a multistate button the property that has the information I need is props.controlValue, for Numeric Entry Fields and Dropdowns the property is props.value. For a text field it is props.text... And so if I obtain the component type then I can tell the code which property to look at.

We should probably add this to the scripting 'wrapper' for Components. I don't really see any reason to obscure this information.

2 Likes

You could use some consistent component prefix convention such as

  • lbl for label,
  • ddn for dropdown,
  • cbx for checkbox
  • etc.
    and then check meta.name for that prefix.

Okay, but why?

At design time you already select the information that you need from the component directly, I wouldn't expect a script to need to generate it dynamically.

This feels like a slippery slope to poor performance to me.

I have a variety of common scripts that collect input data from "forms" in Vision that use similar patterns to access the correct property. It would be nice to have similar capabilities in Perspective. Common scripts are generally a good idea. Hard coding all property access leads to repeating one's self. ):

1 Like

Glad to hear I'm not alone @pturmel.

@lrose I am planning on having 100s of these forms created in the future so I am trying to make global scripts for Startup of the View and ActionPerformed on the Submit button, and since there will be 100s of these forms, I want to make the designer do as little work as possible when configuring each one of these forms. And that includes not having to have the designer manually indicate on each component to reference either props.controlValue or props.value or props.text.