Search code examples
javascriptdojomouseeventmouseleave

How to prevent select in tooltipdialog's select option operation trigger onmouseleave event


With dijit/form/Select in ToolTipDialog. Setting the mouseleaveevent for the dialog. But the event will be triggered when I try to select an option.

Fiddle Link :select changes will trigger tooltipdialog onmouseleave

<script>
    require([
        "dojo/parser",
        "dijit/registry",
         "dijit/TooltipDialog",
        "dijit/form/Select",
        "dijit/popup",
        "dojo/on",
        "dojo/dom",
         "dojo/domReady!"
    ], function(parser,registry,TooltipDialog,Select, popup, on, dom){
        parser.parse();

        var selHucode="";

        var myTooltipDialog = new TooltipDialog({
            id: 'myTooltipDialog',
            style:'height:180px',
            style: "width: 300px;",
            content:  '<div id="tpDialog" class="pDlg"></div><div id="btnGroup" class="left"><label for="name">selectP:</label> <input data-dojo-type="dijit/form/RadioButton">' +
        '<br><label for="hobby"> 1111:</label> <input data-dojo-type="dijit/form/RadioButton"></div>'
        +'<div id="selectMenu" class="right"> <select name="select1" id="sel"   data-dojo-type="dijit/form/Select"> <option value="TN">Tennessee</option>'+
        '<option value="VA" selected="selected">Virginia</option></select></div>' ,
            onMouseLeave: function(e){

                 popup.close(myTooltipDialog);
            },
        onOpen:function(e){

            var sHu=registry.byId("sel");

           sHu.on("focus",function(e){
               console.log(e);
           })
            selHucode=sHu.value;
   //      console.log(sHu.value);
        }
        });



        on(dom.byId("ttt"),"mouseover" , function(e){

            popup.open({
                popup: myTooltipDialog,
                orient: ["above-centered","above","below"],
                around:dom.byId('ttt')

            });

        });


    });
</script>

<span id="ttt"  >  tttt</span>


Solution

  • It's so Simple : in your TooltipDialog onMouseLeave event check if the the mouse is hovering the select using registry getEnclosingWidget method , if it correspond to your select name ('select1') then prevent closing .

    here is the code you'll change :

    onMouseLeave: function(e){
       if(registry.getEnclosingWidget(e.target).name=="select1") return;
       popup.close(myTooltipDialog);
    }
    

    Here is a fiddle if you want to check : Fiddle