How To subscribe on a change/set of a mendix field (widget)

2
In a java script snippet we need to trigger a function to be after the "_setValueAttr" function is called of a normal Mendix field. The Mendix fields are no dojo widget so, dojo.bynode does not give met the object. How can connect to the "_setValueAttr" ? Or can this only done by creating a new widget instead of snippet?
asked
2 answers
1

To get the function working I created a own widget. (did not manage to get it working with a snipet.

This widget will take the value of a attribute and places it as a class to the first parent with the matching target class. This will be useful when you want to style a element in your application based on a value in the database.

dojo.provide("TemplateGridStyle.TemplateGridStyle");
dojo.require("dojo.NodeList-traverse");

mxui.widget.declare('TemplateGridStyle.TemplateGridStyle', {

    inputargs: {
        name: '',
        target: ''
    },

    cssClass: '',

    postCreate : function(){
        this.actRendered();
    },

    _setValueAttr: function (value) {
        //Find target
        var targetNode =  dojo.query(this.domNode).closest("."+this.target)[0];
        //remmove old class
        if(mxui.dom.hasClass(targetNode, this.cssClass))
            mxui.dom.removeClass(targetNode, this.cssClass);
        //add class
        mxui.dom.addClass(targetNode, value);
        this.cssClass = value;
    }
});
answered
-1

If you know the dom node, dojo.attr will give you the widget id. Then you can grab the dojo widget.

dijit.byId(dojo.attr(domNode, "widgetid"))

^This gives you the widget object.

You can add events using dojo.connect

EDIT: If you don't know the domNode of the field you want to look at, you can give it a class while setting up in the modeler. Then you can use dojo.query(".myCustomClass")[0] to grab it.

EDIT # 2: Based on the clarification, you want to format input boxes in a template grid based on their values. You can use something like this.

dojo.query('input.templatesystemTemplateGrid_textBox').forEach( function (obj) {
      if (obj.value === "the value i want") {
          dojo.addClass(obj, "myCustomClassName");
     }
});
//Also, obj.name will give you what you're editing. E.g. Administration.Account/FullName
answered