Skip to content

Commit

Permalink
Tweaks to checkbox & required
Browse files Browse the repository at this point in the history
Fixes #862 and part of #863
  • Loading branch information
tiesont committed Nov 7, 2024
1 parent 5ba822e commit 4403cd0
Show file tree
Hide file tree
Showing 10 changed files with 6,776 additions and 27 deletions.
24 changes: 16 additions & 8 deletions bootbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,20 +582,28 @@
let value;

if (options.inputType === 'checkbox') {
value = input.find('input:checked').map(function () {
return $(this).val();
}).get();
if(options.required === true) {
if(input.find('input:checked').length > 0) {
value = input.find('input:checked').map(function () {
return $(this).val();
}).get();
}
else {
// prevents button callback from being called if no checkboxes have been checked
return false;
}
}
else {
value = input.find('input:checked').map(function () {
return $(this).val();
}).get();
}
} else if (options.inputType === 'radio') {
value = input.find('input:checked').val();
}
else {
let el = input[0];

// Clear any previous custom error message
if(options.errorMessage) {
el.setCustomValidity('');
}

if (el.checkValidity && !el.checkValidity()) {
// If a custom error message was provided, add it now
if(options.errorMessage){
Expand Down
22 changes: 14 additions & 8 deletions dist/bootbox.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,19 +586,25 @@
let value;

if (options.inputType === 'checkbox') {
value = input.find('input:checked').map(function() {
return $(this).val();
}).get();
if (options.required === true) {
if (input.find('input:checked').length > 0) {
value = input.find('input:checked').map(function() {
return $(this).val();
}).get();
} else {
// prevents button callback from being called if no checkboxes have been checked
return false;
}
} else {
value = input.find('input:checked').map(function() {
return $(this).val();
}).get();
}
} else if (options.inputType === 'radio') {
value = input.find('input:checked').val();
} else {
let el = input[0];

// Clear any previous custom error message
if (options.errorMessage) {
el.setCustomValidity('');
}

if (el.checkValidity && !el.checkValidity()) {
// If a custom error message was provided, add it now
if (options.errorMessage) {
Expand Down
2 changes: 1 addition & 1 deletion dist/bootbox.all.min.js

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions dist/bootbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,20 +582,28 @@
let value;

if (options.inputType === 'checkbox') {
value = input.find('input:checked').map(function () {
return $(this).val();
}).get();
if(options.required === true) {
if(input.find('input:checked').length > 0) {
value = input.find('input:checked').map(function () {
return $(this).val();
}).get();
}
else {
// prevents button callback from being called if no checkboxes have been checked
return false;
}
}
else {
value = input.find('input:checked').map(function () {
return $(this).val();
}).get();
}
} else if (options.inputType === 'radio') {
value = input.find('input:checked').val();
}
else {
let el = input[0];

// Clear any previous custom error message
if(options.errorMessage) {
el.setCustomValidity('');
}

if (el.checkValidity && !el.checkValidity()) {
// If a custom error message was provided, add it now
if(options.errorMessage){
Expand Down
2 changes: 1 addition & 1 deletion dist/bootbox.min.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion karma-base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(params) {
['tests/**/*.test.js']
),
exclude: [],
reporters: ['dots', 'coverage', 'junit'],
reporters: ['dots', 'coverage', 'junit', 'progress', 'html'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
Expand All @@ -31,6 +31,18 @@ module.exports = function(params) {

junitReporter: {
outputDir: 'tests/reports'
},

htmlReporter: {
outputFile: 'tests/units.html',

// Optional
pageTitle: 'Bootbox',
subPageTitle: 'Unit test results, Grouped',
groupSuites: true,
useCompactStyle: true,
useLegacyStyle: false,
showOnlyFailed: false
}
});
};
Expand Down
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.1",
"karma-coverage": "^2.2.0",
"karma-htmlfile-reporter": "^0.3.8",
"karma-junit-reporter": "^2.0.1",
"karma-mocha": "^2.0.1",
"karma-sinon-chai": "^2.0.2",
Expand Down
Loading

0 comments on commit 4403cd0

Please sign in to comment.