Start Simple
Let's just create a dialog with a textbox on it, along with a simple onclick trigger:
<div onclick="showDialog()">clickme</div> <br> <br> <div id="dialogTarget">dialog appears here</div> <script type="text/javascript"> dojo.require("dijit.form.TextBox"); dojo.require("dijit.TooltipDialog"); var dialog; dojo.addOnLoad(function(){ var tb = new dijit.form.TextBox({name:"tb1"}); dialog = new dijit.TooltipDialog({ content: tb, onBlur: function() { dijit.popup.close(dialog); } }); }); function showDialog(){ dijit.popup.open({ popup: dialog, around: dojo.byId("dialogTarget") }); } </script>
A few things to note about this code - the content of a tooltip can be a dijit widget or HTML in quotes, and we can make the toolip appear on any element of our choice using the dijit.popup function. Most examples I could find showed content as HTML and the display of the tooltip triggered by a dijit.form.DropDownButton, neither of which fit my needs.
Change the Content
So what happens if the content of the tooltip dialog needs to be changed at runtime? This can be addressed using the attr() function:
<div onclick="showDialog(false)">clickme</div> <div onclick="showDialog(true)">clickme again</div> <br> <br> <div id="dialogTarget">dialog appears here</div> <script type="text/javascript"> dojo.require("dijit.form.TextBox"); dojo.require("dijit.form.NumberSpinner"); dojo.require("dijit.TooltipDialog"); var dialog; dojo.addOnLoad(function(){ var tb = new dijit.form.TextBox({name:"tb1"}); dialog = new dijit.TooltipDialog({ content: tb, onBlur: function() { dijit.popup.close(dialog); } }); }); function showDialog(changeContents){ if (changeContents){ var mySpinner = new dijit.form.NumberSpinner({ value: 1000, smallDelta: 10, constraints: { min: 9, max: 1550, places: 0 }, style: "width:100px" }); dialog.attr("content", mySpinner); } dijit.popup.open({ popup: dialog, around: dojo.byId("dialogTarget") }); } </script>In this code I've made a few changes to support two options - clicking on one element (clickme) will show the dialog we created in the first example, and another (clickme again) will change the contents of the dialog with a dijit.form.NumberSpinner. The key line of code here is dialog.attr("content", mySpinner).
Try it here.
It's wonderful article...very much fits into my needs
ReplyDeletedoes not work 4 grid
ReplyDeleteLike it,
ReplyDeleteI have a similar problem. Changing the content I'm using dailog.set( "content", markup).
However, how can I achieve that dialog closes when user klicks outside of dialog?
greets ck
use onBlur like in sample
Delete