Page 1 of 1

Creating a derived custom widget and initialization

Posted: Tue Apr 16, 2019 6:41 pm
by JacobPreston
I saw the example of creating a derived custom widget at http://www.profoundlogic.com/docs/displ ... ved+widget

Is it possible to create an initialization function to call when the derived widget is loaded?
For example, in the example for creating a custom widget from scratch at http://www.profoundlogic.com/docs/displ ... om+Scratch
The "field type" property of propertySetters is initialized to a function for initializing the widget.

Is there a way to do something like this for a custom derived widget? I tried setting the "field type" property to a function, but it does not appear to be firing when the widget is loaded.

For reference, this is what I tried just to see if I could get the "field type" event to fire when the widget is loaded. Will I have to create the widget from scratch in order to get this functionality?

Code: Select all

pui.toolbox.add({
  category: "Custom Widgets",
  widget: "select box",  
  text: "Custom List Box Test",
  icon: "/profoundui/proddata/images/icons/list_box.png",   
  // any property of a "select box" can be altered here
  defaults: {
    "select box height": "5",
    "width": "150px",
    "color": "#666666",
    "background color": "#FAE4AA",
    "choices": "Choice 1",
    "font family": "Sans-Serif",
    "font size": "12px"
  },
  // property setter functions
  propertySetters: {
 
    // this will fire when the field type property is set to "select box"
    "field type": function(parms) {
      if (parms.design) {

      }
      else 
      {
      	alert("This is a test to see if the field type property is firing for our custom derived widget.")                                                                                                                                    
      }
      }
    }, 
});

Re: Creating a derived custom widget and initialization

Posted: Wed Apr 17, 2019 10:40 am
by Scott Klement
A "derived" widget is one of the existing widgets added to the toolbox with different default properties.

Since you're not actually coding the widget, there's nowhere to put code that would run when the widget runs.

So, the answer is "no".