Error accessing template nodes in custom widget class

700
2
Jump to solution
09-30-2016 08:34 AM
CarlosSousaFerreira
New Contributor III

Hi,

I'm creating a new widget class for dinamically sellecting some data from a list of records provided and retrieving it to a custom widget.

I have called this new widget class MyFieldsSelect and I created two files, one for the code (.js) and other for the template (.html) and placed them inside the folder of my custom widget.

Here is the begining code of my MyFieldsSelect.js:

define([
    'dojo/_base/declare',
    'dijit/_WidgetBase',
    'dijit/_WidgetsInTemplateMixin',
    'dojo/text!./MyFieldsSelect.html',
    'dojo/_base/lang',
    'dojo/on',
    'dojo/dom-style',
    'dojo/dom-attr',
    'dojo/dom-construct',
    'dojo/_base/array',
    './FieldSelector'
  ],
  function (declare, _WidgetBase, _WidgetsInTemplateMixin,
    MyFieldsSelectTemplate, lang, on, domStyle,
    domAttr, domConstruct, array, FieldSelector) {

    var clazz = declare([_WidgetBase, _WidgetsInTemplateMixin], {
      baseClass: 'jimu-widget-MyFieldsSelect-setting',
      templateString: MyFieldsSelectTemplate,

I used _WidgetBase because it was the only way I manage to define a constructor method and work properly with the arguments passed in the instantiation of an object of this class.

My problem is that I'am not being able to access the data-dojo-attach-points that I defined in my template (MyFieldsSelect.html), and, when I try to access an element through this.myElementDataDojoAttachPointName, it says it is undefined, although the variable templateString returns the content of my template file as text.

Any ideas on how to correct this?

Thanks

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Carlos,

   You need the 'dijit/_TemplatedMixin', require and to include it in your declare too.

define([
    'dojo/_base/declare',
    'dijit/_WidgetBase',
    'dijit/_TemplatedMixin',
    'dijit/_WidgetsInTemplateMixin',
    'dojo/text!./MyFieldsSelect.html',
    'dojo/_base/lang',
    'dojo/on',
    'dojo/dom-style',
    'dojo/dom-attr',
    'dojo/dom-construct',
    'dojo/_base/array',
    './FieldSelector'
  ],
  function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin,
    MyFieldsSelectTemplate, lang, on, domStyle,
    domAttr, domConstruct, array, FieldSelector) {

    var clazz = declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Carlos,

   You need the 'dijit/_TemplatedMixin', require and to include it in your declare too.

define([
    'dojo/_base/declare',
    'dijit/_WidgetBase',
    'dijit/_TemplatedMixin',
    'dijit/_WidgetsInTemplateMixin',
    'dojo/text!./MyFieldsSelect.html',
    'dojo/_base/lang',
    'dojo/on',
    'dojo/dom-style',
    'dojo/dom-attr',
    'dojo/dom-construct',
    'dojo/_base/array',
    './FieldSelector'
  ],
  function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin,
    MyFieldsSelectTemplate, lang, on, domStyle,
    domAttr, domConstruct, array, FieldSelector) {

    var clazz = declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
0 Kudos
CarlosSousaFerreira
New Contributor III

One more crushed bug... Thank you, Robert!

0 Kudos