BPM, Workflow, and Case

BPM, Workflow, and Case

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
  • 1.  Error finding dojo widget in registry when it's not at top level

    Posted Thu August 06, 2020 05:39 PM
    Hi Guys,

    I have a simple custom coach view to rate anything. It uses the dojox/form/Rating widget, and works fine if I place it on a coach, but do not work if I place it inside another coach view like a Horizontal Layout or any other coach view. The problem is that the registry.byId dojo function do not find the widget if my coach view isn't at top level (i.e. on the coach).

    Here is the AMD dependency list:

    Here is the HTML content:
    <div class="Rating" id="$$viewDOMID$$_Rating" data-dojo-type="dojox.form.Rating" data-dojo-props="numStars:5"></div>

    And here is the code of the load event of the coach view:

    var _this = this;
    var _widget = registry.byId(_this.context.viewid + "_Rating");

    console.log(_widget);               // _wiget is undefined if the coach view isn't placed at top level of the coach
    console.log(registry.toArray()); // registry array always contains the Rating widget, even when it is invisible for the registry.byId

    // If there is bind variable, set the value of the Rating widget
    if (_this.context.binding != undefined) {
         _widget._setValueAttr(_this.context.binding.get("value"));
    }

    // On changing the value (i.e. clicking on a star) set the value of the bind variable if it is assigned to the coach view
    dojo.connect(_widget, "onChange", function() {
         if (_this.context.binding != undefined) {
              _this.context.binding.set("value", _widget.value);
         }
    });


    Here is the console output when the coach view was placed within another coach view (see the two console.log(...) lines above):



    What's wrong? Why do not find the registry.byId function the Registry widget if it is placed inside another coach view, and why do it find the widget if it is at top level, or with other words it's placed on the coach? How to solve this problem?

    Any help appreciated!
    Thx,
    Laszlo



  • 2.  RE: Error finding dojo widget in registry when it's not at top level
    Best Answer

    Posted Fri August 07, 2020 01:55 AM
    Edited by Ted Will Fri August 07, 2020 09:31 AM
    Hi Laszlo,

    Can you try to create the widget programmatically like - 

    var _this = this;
    
    _this.ratingWidget = new Rating({
    	numStars: 5,
    });
    
    if (_this.context.binding != undefined) {
         _this.ratingWidget._setValueAttr(_this.context.binding.get("value"));
    }
    
    domConstruct.place(_this.ratingWidget.domNode, _this.context.element);
    
    dojo.connect(_this.ratingWidget, "onChange", function() {
         if (_this.context.binding != undefined) {
              _this.context.binding.set("value", _this.ratingWidget.value);
         }
    });

    Hope this would resolve your problem.



    ------------------------------
    Atanu Roy
    ------------------------------



  • 3.  RE: Error finding dojo widget in registry when it's not at top level

    Posted Fri August 07, 2020 03:38 AM
    Hi Atanu,

    This way it works fine! Many thanks!


    ------------------------------
    Laszlo
    ------------------------------