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.