How to trigger a checkbox checked event

6425
4
Jump to solution
06-08-2018 12:01 PM
HelenZhou
Occasional Contributor II

I have a widget that is adapted from the Addlayer widget (AddLayer Widget  by  softwhere). The widget has two items - the top is a dijit.form.Select and bottom is a listview(see attached picture). When a box is checked, a layer is loaded to a map. What I would like to implement is - once a new item is selected from the select dropdown list, certain layers in the layer list are checked, which triggers the  onLayerSelected event, so that the map services associated with those layers are loaded to the map. I write an onSelectChange event, which get the related checkbox, and set its checked to be true. Codes are running fine, but the box is not checked and the onLayerSelected is not triggered. Do I miss anything? Thanks so much.

Helen

widget,html-

<div>
    <!--<div class="help-text">Check the additional layers to add to the map</div>-->
    <div>
        <input type="select" data-dojo-type="dijit/form/Select" data-dojo-props="name:'theme',style:'width:100%;'"
               data-dojo-attach-point="themeDijit" data-dojo-attach-event="Change:onSelectChange" />
    </div>
    <div class="layer-list-body" data-dojo-attach-point="layerListBody">
        <!-- layer list table added here-->
    </div>
    <hr />
    <div data-dojo-attach-point="message"></div>
</div>

widget.js -

            onSelectChange: function (newValue) {
                var fields = newValue.split(',');
                array.forEach(this.config.layers, function (layer) {
                    if (layer.name === "Fire") {
                        var cb = registry.byId("Fire");  //checkbozx is found
                        cb.set("checked", true); //checked property is set. But the check box is not checked in the widget

                                                               //and onLayerSelected is not fired?
                    }
              
                }, this);
            },

            onLayerSelected: function (evt) {
                var layer = evt.layer;
                this.addLayerToMap(layer);
            },

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Helen,

   You just need to use setValue of the checkBox not set the checked attribute.

cb.setValue(true);

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Helen,

   There is nothing in the jimu/dijit/CheckBox that would cause the checked property to fire the click event which is what the LayerListView.js is listening for to fire the _onLayerCheckNodeClick

0 Kudos
HelenZhou
Occasional Contributor II

Thanks Robert. Do you why the checkbox is not checked in the widget even though I specify in the code as  - cb.set("checked", true)?

I am able to see the checkbox's checked property to be true.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   You just need to use setValue of the checkBox not set the checked attribute.

cb.setValue(true);

HelenZhou
Occasional Contributor II

Hi Robert,

Magic! Thanks so much.

Helen

0 Kudos