How to create new widget html nodes (objects) that call a function in widget.js when clicked

2205
4
07-02-2015 08:23 AM
MikeWottrich
New Contributor II

Hello,

I am looking for pointers on how to create new html nodes (objects) that call a function in widget.js when clicked. I can add new buttons through javascript and add a click event to a javascript function, but cannot seem to fire a function that is within widget.js  I'm sure this is fairly straight forward, but was hoping to get some help from seasoned programmers on how to do it and best practices.

It seems like an html button that is already there when the widget opens can fire use functions in widget.js, but new ones are causing me a problem.

Any and all help would be greatly appreciated.

thanks,

Mike

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Mike,

   I don't do a lot of dynamic building of objects though JS in my widgets. I normally have everything templated out and the html already has all the html buttons, etc with "data-dojo-attach-point" and "data-dojo-attach-event" already assigned. Is there a reason that you can not design dijits for the portions of your widget that has to dynamically change?

Your issue is likely a scoping issue where your click event is in a different scope than your functions and thus your inability to call them, so are you using lang.hitch?

MikeWottrich
New Contributor II

Thanks for replying Robert.

Basically, I am creating a list(s) of selected features that the user should be able to remove from a given list and/or zoom to (review) before submitting. The list(s) of features may will come from different layers and will be appended to as required. Essentially, it is a very dynamic list of selected features. I can add a 'Zoom To' button to the widget that will act on a selected feature from the list which has "data-dojo-attach-point" and "data-dojo-attach-event" already assigned so I can make the actions happen, but I thought it would be more intuitive for the user to have a zoom button per feature.

I beleive you are correct about it being a scoping issue and will do some more review in that area before continuing. I am not using lang.hitch at the moment.

Thanks again for your help and I will let you know how it goes.

Mike

0 Kudos
PrevinWong1
Esri Contributor

Mike,

When you create your dynamic feature list, you need to lang.hitch them during that time otherwise run time, the scope will be off as you mentioned.

this.own(on(Node, 'click', lang.hitch(this, "MyWidgetJSFunctionInTheseQoutes", param1, param2, etc)));

Hope this helps.

MikeWottrich
New Contributor II

Thank you Previn.

I will let you know how it goes.

Mike

0 Kudos