ideally when i a click a action item in my table it shows "show message" on clicking on to it i need a popup without the use of window.alert or alert instead show a pop up based on my website design
function showFailedWarning(){
dijit.byId('validationsForm').clearMessages();
dijit.byId('validationsForm').popup(alert("Upload Correct File "));
}
ideally when i a click a action item in my table it shows "show message" on clicking on to it i need a popup without the use of window.alert or alert instead show a pop up based on my website design
function showFailedWarning(){
dijit.byId('validationsForm').clearMessages();
dijit.byId('validationsForm').popup(alert("Upload Correct File "));
}
Share
Improve this question
edited Jul 23, 2013 at 18:35
Craig Swing
8,1622 gold badges32 silver badges43 bronze badges
asked Jul 23, 2013 at 18:31
Prem ChandranPrem Chandran
551 gold badge2 silver badges8 bronze badges
3
- Try jQuery UI Dialog: jqueryui./dialog/#modal-message – Jason P Commented Jul 23, 2013 at 18:40
- Even leaner and cleaner is NOTY: needim.github.io/noty – DevlshOne Commented Jul 23, 2013 at 18:45
-
@DevlshOne Both still require
jQuery
or an additionnal library to work. – Jeff Noel Commented Jul 23, 2013 at 19:10
2 Answers
Reset to default 6Method #1 - Pure JavaScript
You can build your own pop-up with whatever design you want. Either hardcode the elements in HTML and set display:none
to the container in CSS, or dynamically append the container.
Note: Why I used innerHTML
in place of appendChild()
.
Live Demo
HTML
<button id="error">Click for error</button>
JavaScript
document.getElementById('error').onclick = function (event) {
event.preventDefault();
/*Creating and appending the element */
var element = '<div id="overlay" style="opacity:0"><div id="container">';
element += "<h1>Title</h1><p>Message</p>";
element += "</div></div>";
document.body.innerHTML += (element);
document.getElementById('overlay').style.display = "block";
/* FadeIn animation, just for the sake of it */
var fadeIn = setInterval(function () {
if (document.getElementById('overlay').style.opacity > 0.98) clearInterval(fadeIn);
var overlay = document.getElementById('overlay');
overlay.style.opacity = parseFloat(overlay.style.opacity, 10) + 0.05;
console.log(parseFloat(overlay.style.opacity, 10));
}, 50);
};
CSS
#overlay {
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
z-index:1000;
background-color: rgba(0, 0, 0, 0.5);
opacity:0;
display:none;
}
#container {
position:absolute;
top:30%;
left:50%;
margin-left:-200px;
width: 400px;
height:250px;
background-color:#111;
padding:5px;
border-radius:4px;
color:#FFF;
}
Method #2 - Third-party libraries
You can use libraries such as jQuery UI
to achieve what you want:
Live Demo
HTML
<button id="error">Click for error</button>
JavaScript/jQuery
$('#error').click(function (event) {
event.preventDefault();
$('<div id="container"><h1>Error</h1><p>Message</p></div>').dialog({
title: "Error"
});
});
Since you this question has the dojo tag and you have dijit code in your example, I would suggest using dijit.Dialog
to do this.
I put together a quick example on jsfiddle demonstrating it.
require(['dijit/Dialog', 'dijit/form/Button'], function (Dialog, Button) {
//create a new button (doesn't matter if it is programmatically or not)
var button = new Button({
label: 'Validate',
type: 'button'
});
button.placeAt(dojo.body());
button.on('click', function () {
//instantiate the dialog with our error message and content
var dialog = new Dialog({
title:'Error Message title',
content: '<div>Something is invalid!</div>',
style:'min-width:300px;'
});
//show the error message
dialog.show();
});
});
The dojo docs for dijit/Dialog should also be helpful to look at.