Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 6.0.4 (Latest Release)
## 6.0.5 (Latest Release)

- Updates prompt input validation to apply `was-validated` class to form when **OK** button is clicked
- Updates prompt input to trigger form submit when "enter" key is pressed

### 6.0.4

- Updates `step` to allow setting value for date inputs

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Bootbox **3.3.0** is the *last* release to support Bootstrap 2.2.x.

Much more dependency information can be found [on the Bootbox website](http://bootboxjs.com/getting-started.html#bootbox-dependencies).

## 6.0.4 (Latest Release)
## 6.0.5 (Latest Release)

- Updates `step` to allow setting value for date inputs
- Updates prompt input validation to apply `was-validated` class to form when **OK** button is clicked
- Updates prompt input to trigger form submit when "enter" key is pressed

For a full list of releases and changes please see [the changelog](https://github.com/bootboxjs/bootbox/blob/master/CHANGELOG.md).

Expand Down
53 changes: 39 additions & 14 deletions bootbox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! @preserve
* bootbox.js
* version: 6.0.4
* version: 6.0.5
* author: Nick Payne <nick@kurai.co.uk>
* license: MIT
* http://bootboxjs.com/
Expand All @@ -10,10 +10,12 @@
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
}
else if (typeof exports === 'object') {
// Node, CommonJS-like
module.exports = factory(require('jquery'));
} else {
}
else {
// Browser globals (root is window)
root.bootbox = factory(root.jQuery);
}
Expand All @@ -22,7 +24,7 @@

let exports = {};

let VERSION = '6.0.4';
let VERSION = '6.0.5';
exports.VERSION = VERSION;

let locales = {
Expand Down Expand Up @@ -171,7 +173,8 @@
if (arguments.length === 2) {
// Allow passing of single key/value...
values[arguments[0]] = arguments[1];
} else {
}
else {
// ... and as an object too
values = arguments[0];
}
Expand Down Expand Up @@ -581,6 +584,8 @@
options.buttons.confirm.callback = function () {
let value;

form.addClass('was-validated');

if (options.inputType === 'checkbox') {
value = input.find('input:checked').map(function () {
return $(this).val();
Expand All @@ -589,25 +594,32 @@
// prevents button callback from being called if no checkboxes have been checked
return false;
}
} else if (options.inputType === 'radio') {
}
else if (options.inputType === 'radio') {
value = input.find('input:checked').val();
}
else {
let el = input[0];

// this must be done every time; otherwise, input is reported invalid even if value is valid
el.setCustomValidity('');

// trigger built-in validation if checkValidity() function is defined
if (el.checkValidity && !el.checkValidity()) {
// If a custom error message was provided, add it now
if(options.errorMessage){
el.setCustomValidity(options.errorMessage);
}

if(el.reportValidity) {
// trigger built-in validation message if reportValidity() function is defined
if (el.reportValidity) {
el.reportValidity();
}

// prevents button callback from being called
return false;
} else {
}
else {
if (options.inputType === 'select' && options.multiple === true) {
value = input.find('option:selected').map(function () {
return $(this).val();
Expand All @@ -617,7 +629,7 @@
value = input.val();
}
}
}
}

return options.callback.call(this, value);
};
Expand All @@ -638,6 +650,15 @@
// Create the input based on the supplied type
input = $(templates.inputs[options.inputType]);

if (options.inputType !== 'textarea') {
input.on('keydown', function(ev) {
if (ev.key === 'Enter') {
ev.preventDefault();
promptDialog.find('.bootbox-accept').trigger('click');
}
});
}

switch (options.inputType) {
case 'text':
case 'textarea':
Expand All @@ -661,9 +682,9 @@
input.prop({ 'required': true });
}

if (options.rows && !isNaN(parseInt(options.rows))) {
if (options.inputType === 'textarea') {
input.attr({ 'rows': options.rows });
if (options.inputType === 'textarea') {
if (options.rows && !isNaN(parseInt(options.rows))) {
input.attr({ rows: options.rows });
}
}
break;
Expand Down Expand Up @@ -855,6 +876,8 @@
// Fix for SammyJS (or similar JS routing library) hijacking the form post.
e.stopPropagation();

form.removeClass('was-validated');

// @TODO can we actually click *the* button object instead?
// e.g. buttons.confirm.click() or similar
promptDialog.find('.bootbox-accept').trigger('click');
Expand Down Expand Up @@ -914,7 +937,8 @@
if (argsLength === 2 || typeof args[0] === 'string') {
options[properties[0]] = args[0];
options[properties[1]] = args[1];
} else {
}
else {
options = args[0];
}

Expand Down Expand Up @@ -1035,7 +1059,8 @@
// Make sure backdrop is either true, false, or 'static'
if (!options.backdrop) {
options.backdrop = (options.backdrop === false || options.backdrop === 0) ? false : 'static';
} else {
}
else {
options.backdrop = typeof options.backdrop === 'string' && options.backdrop.toLowerCase() === 'static' ? 'static' : true;
}

Expand Down
30 changes: 24 additions & 6 deletions dist/bootbox.all.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! @preserve
* bootbox.js
* version: 6.0.4
* version: 6.0.5
* author: Nick Payne <nick@kurai.co.uk>
* license: MIT
* http://bootboxjs.com/
Expand All @@ -22,7 +22,7 @@

let exports = {};

let VERSION = '6.0.4';
let VERSION = '6.0.5';
exports.VERSION = VERSION;

let locales = {
Expand Down Expand Up @@ -585,6 +585,8 @@
options.buttons.confirm.callback = function() {
let value;

form.addClass('was-validated');

if (options.inputType === 'checkbox') {
value = input.find('input:checked').map(function() {
return $(this).val();
Expand All @@ -598,12 +600,17 @@
} else {
let el = input[0];

// this must be done every time; otherwise, input is reported invalid even if value is valid
el.setCustomValidity('');

// trigger built-in validation if checkValidity() function is defined
if (el.checkValidity && !el.checkValidity()) {
// If a custom error message was provided, add it now
if (options.errorMessage) {
el.setCustomValidity(options.errorMessage);
}

// trigger built-in validation message if reportValidity() function is defined
if (el.reportValidity) {
el.reportValidity();
}
Expand Down Expand Up @@ -640,6 +647,15 @@
// Create the input based on the supplied type
input = $(templates.inputs[options.inputType]);

if (options.inputType !== 'textarea') {
input.on('keydown', function(ev) {
if (ev.key === 'Enter') {
ev.preventDefault();
promptDialog.find('.bootbox-accept').trigger('click');
}
});
}

switch (options.inputType) {
case 'text':
case 'textarea':
Expand All @@ -665,10 +681,10 @@
});
}

if (options.rows && !isNaN(parseInt(options.rows))) {
if (options.inputType === 'textarea') {
if (options.inputType === 'textarea') {
if (options.rows && !isNaN(parseInt(options.rows))) {
input.attr({
'rows': options.rows
rows: options.rows
});
}
}
Expand Down Expand Up @@ -864,6 +880,8 @@
// Fix for SammyJS (or similar JS routing library) hijacking the form post.
e.stopPropagation();

form.removeClass('was-validated');

// @TODO can we actually click *the* button object instead?
// e.g. buttons.confirm.click() or similar
promptDialog.find('.bootbox-accept').trigger('click');
Expand Down Expand Up @@ -1204,7 +1222,7 @@

/*! @preserve
* bootbox.locales.js
* version: 6.0.4
* version: 6.0.5
* author: Nick Payne <nick@kurai.co.uk>
* license: MIT
* http://bootboxjs.com/
Expand Down
4 changes: 2 additions & 2 deletions dist/bootbox.all.min.js

Large diffs are not rendered by default.

Loading