Custom Widget: Attribute name / value issue from XML

0
Hey guys, This issue has probably popped up quite some time and I only found 1 forum topic from 6 year back about this issue. And for me it seemed like I was missing some documentation for this (apparently my Googling skills are not as advanced :P). So Custom Widget I have a "name" attribute.  Now when I call the key in the custom widget I get "name" instead of "John Doe".  I've read something about using mxobject.get(key) which my widget responds to with "mxobject is not defined" Same for mx.data.get(key) (where I need GUID not key).  I'm currently using: widget-base-master from Jelte Langedijk (JelteMX is GitHub). Package json name: mendix-widget-webpack, readme says it's part of "generator-mendix-widget".  Basically using " yarn run build " or " dev " to compile the widget. So I might be missing some "basic dojo/mx elements here as library input". 
asked
2 answers
4

Hi Jermaine,

Cool that you are trying to use the widget-base in ES6 to build a widget. In order to get the value of this attribute, you will need to first get the context object.

I have an example here:

https://gist.github.com/JelteMX/67b132541586e29f757be3bb20518031

A more sophisticated example is the Leaflet Maps widget, you can find examples here: https://github.com/mendix/Leaflet/blob/master/src/Leaflet/widget/Leaflet.js

answered
4

mxobject.get(key) is correct. In order to get a reference to an mxobject you need either to do an mx.data.get first or get the object from the context i.e. this._contextObj

I always find it usefull to take a look at how other widget work when I am struggling with some part of the mendix client API. See for example - https://github.com/mendix/BooleanSlider/blob/master/src/BooleanSlider/widget/BooleanSlider.js

answered