Passing properties to custom class

I’m creating a widget which is similar to the YesNoMaybeItem. When you click the ellipses a window pops up. I want to define properties in the instance in the form, but they don’t seem to be getting passed to the object.

All I want is the “chooserTitle” property to be accessible within the class. But it’s undefined in the class.

In the form I have:

{ name: "SlideImageUrl", title: "Show Slide", type: "string", chooserTitle: "Slide Image Chooser", editorType: "YesNoMaybeItem"},
/*---------->    YesNoMaybeItem.js    <----------*/


// subclass either TextItem or StaticTextItem, depending on whether we
// provide a free-form edit field as well as the value picker
ClassFactory.defineClass("YesNoMaybeItem", TextItem);

// class (static) properties and methods
YesNoMaybeItem.addClassProperties({
    // (just placeholders for now - these are set dynamically)
    dialog: null,
    currentEditor: null,

    // create the picker dialog
    makeDialog: function() {
       Log.logWarn("YesNoMaybeItem chooserTitle: " + this.chooserTitle);
Log.logWarn("YesNoMaybeItem chooserTitle: " + YesNoMaybeItem.chooserTitle);

        YesNoMaybeItem.dialog = Dialog.create({
            autoDraw: false,
            autoCenter: false,
            isModal: true,
            showHeader: false,
            showToolbar: false,
            width: 130,
            height: 110,
            bodyDefaults: { layoutMargin: 10, membersMargin: 10 },
            items: [
				Button.create({ title: "YES", click: "YesNoMaybeItem.setValue(this.title)" }),
				Button.create({ title: "NO", click: "YesNoMaybeItem.setValue(this.title)" }),
				Button.create({ title: "MAYBE", click: "YesNoMaybeItem.setValue(this.title)" })
			]
        });
    },
    // show the picker dialog at the specified position (could be smarter about this)
    showDialog: function(left, top) {
        this.dialog.moveTo(left, top);
        this.dialog.show();
    },
    // set the specified value and dismiss the picker dialog
    setValue: function(value) {
        this.currentEditor.setValue(value);
        this.dialog.hide();
    }
});

// instance properties and methods
YesNoMaybeItem.addProperties({
    chooserTitle: "",
    icons: [{}], // could specify a different image here

    // (this logic could alternatively go on the 'click' handler of the icon object)
    iconClick: function(form, item, icon) {
       
Log.logWarn("YesNoMaybeItem chooserTitle: " + this.chooserTitle);
Log.logWarn("YesNoMaybeItem chooserTitle: " + YesNoMaybeItem.chooserTitle);

        // get global coordinates of the clicked picker icon
        var iconRect = this.getIconPageRect(icon);

        // lazily create the YesNoMaybe picker dialog the first time a yesNoMaybe editor is clicked
        if (!YesNoMaybeItem.dialog) YesNoMaybeItem.makeDialog();

        // remember what editor is active, so we can set its value from the picker dialog
        YesNoMaybeItem.currentEditor = this;

        // show the picker dialog
        YesNoMaybeItem.showDialog(iconRect[0], iconRect[1]);
    }
});

Thanks

Paul

Sorry, I looked through the documentation for over 1 1/2 hours before posting the question and then found the solution about 30 minutes later.

I’m assigning the properties to the local properties.

My real control name is ImageSelectorItem:

ImageSelectorItem.addProperties({
    fileLocationBase: "",
    fileLocationPath: "",
    chooserTitle: "",
init: function() {

       
        ImageSelectorItem.fileLocationBase = this.fileLocationBase;
        ImageSelectorItem.fileLocationPath = this.fileLocationPath;
        ImageSelectorItem.chooserTitle = this.chooserTitle;
        this.Super("init", arguments);

    
    },

...

Then, in the class properties:

ImageSelectorItem.addClassProperties({
  makeWindow: function() {
     ImageSelectorItem.window = Window.create({
            ID: ImageSelectorItem.baseName + "Window",
            title: ImageSelectorItem.chooserTitle

Does this make sense or am I making it more complicated than it needs to be?

If you just want an instance property: use addProperties(), you don’t need your init() override, and it’s accessible as this.propertyName anywhere in a method of that class, after init() has been called (see addPropertiesOnCreate for details on this).

If for some reason you want it as a class property, just add it via addClassProperties() and it’s accessible as isc.className.propertyName.