$.alert
adds one button (okay) if no buttons are specified, this lets the user to close the modal.
.alert({
title: 'Alert!',
content: 'Simple alert!',
});
$.confirm
if no buttons are specified, two buttons (Okay & cancel) will be added.
$.confirm({
title: 'Confirm!',
content: 'Simple confirm!',
buttons: {
confirm: function () {
$.alert('Confirmed!');
},
cancel: function () {
$.alert('Canceled!');
},
somethingElse: {
text: 'Something else',
btnClass: 'btn-blue',
keys: ['enter', 'shift'],
action: function(){
$.alert('Something else?');
}
}
}
});
Showing prompt using confirm
Simply add form to the content and bind the events you want.
This form can also be loaded via ajax.
$.confirm({
title: 'Prompt!',
content: '' +
'<form action="" class="formName">' +
'<div class="form-group">' +
'<label>Enter something here</label>' +
'<input type="text" placeholder="Your name" class="name form-control" required />' +
'</div>' +
'</form>',
buttons: {
formSubmit: {
text: 'Submit',
btnClass: 'btn-blue',
action: function () {
var name = this.$content.find('.name').val();
if(!name){
$.alert('provide a valid name');
return false;
}
$.alert('Your name is ' + name);
}
},
cancel: function () {
//close
},
},
onContentReady: function () {
// bind to events
var jc = this;
this.$content.find('form').on('submit', function (e) {
// if the user submits the form by pressing enter in the field.
e.preventDefault();
jc.$$formSubmit.trigger('click'); // reference the button and click it
});
}
});
$.dialog
removes buttons and explicitly shows the closeIcon (×)
$.dialog({
title: 'Text content!',
content: 'Simple modal!',
});
NOTE : The $.confirm()
, $.dialog()
& $.alert()
methods are alias of jconfirm()
.
All three methods indirectly call the jconfirm base function altering the provided options.