SetAttribute for other object from a widget

0
Hi mates I tried to set value of a textbox by javascript, but it seems not be stored. After some research, I found mxobj.setAttribute, but failed to get the object. How can I do that? Simon A little further information: This is a graphical widget contained in a data view. Upon clicking on an area in the widget, we wish to set a value to a text attribute of the containing data view. The following have been added to the widget: needsEntityContext="true" is set in the xml file In the widget the following are included.. addons: [ dijit._Contained, mendix.addon._Contextable ], also this.initContext(); (in the postCreate function) and applyContext : function(context, callback){ logger.debug(this.id + ".applyContext"); if (context) mx.processor.getObject(context.getActiveGUID(), dojo.hitch(this, this.setDataobject)); else logger.warn(this.id + ".applyContext received empty context"); callback && callback(); }, So, the questions is how do we then refer to an attribute of the data view to be able to set the value? Thanks for any suggestions
asked
1 answers
5

The example code below should give you an idea of how you can manipulate a Mendix object in a widget. The data view object will be passed to the update method, together with a callback function which should be called when the widget is done.

mxui.widget.declare("TestModule.TestWidget", {
    inputargs: {
        attrName: ""
    },
    mxObject: null,

    update: function(obj, callback) {
        this.mxObject = obj;

        // Show the attribute value if an object is passed. Else
        // clear the widget's value. TODO: enable / disable widget.
        this.set("value", obj ? obj.get(this.attrName) : "");
    },

    onChange: function() {
        // Update the object with the new attribute value.
        this.mxObject.set(this.attrName, this.get("value"));
    },

    _setValueAttr: function(value) {
        // Render value to the DOM node.
    },

    _getValueAttr: function() {
        // Get value from the DOM node.
    }
});

The onChange method should be called when the widget's value is changed.

answered