Skip to content

Commit

Permalink
Adds pattern fallback for date and time inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
tiesont committed Nov 10, 2022
1 parent c0541a7 commit 686963a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions bootbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,16 @@
if (options.pattern) {
input.attr('pattern', options.pattern);
}
else {
if(options.inputType === 'date') {
// Add the ISO-8601 short date format as a fallback for browsers without native type="date" support
input.attr('pattern', '\d{4}-\d{2}-\d{2}');
}
else if(options.inputType === 'time') {
// Add an HH:MM pattern as a fallback for browsers without native type="time" support
input.attr('pattern', '\d{2}:\d{2}');
}
}

if (options.required) {
input.prop({ 'required': true });
Expand Down
8 changes: 8 additions & 0 deletions dist/bootbox.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,14 @@

if (options.pattern) {
input.attr('pattern', options.pattern);
} else {
if (options.inputType === 'date') {
// Add the ISO-8601 short date format as a fallback for browsers without native type="date" support
input.attr('pattern', '\d{4}-\d{2}-\d{2}');
} else if (options.inputType === 'time') {
// Add an HH:MM pattern as a fallback for browsers without native type="time" support
input.attr('pattern', '\d{2}:\d{2}');
}
}

if (options.required) {
Expand Down
2 changes: 1 addition & 1 deletion dist/bootbox.all.min.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions dist/bootbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,16 @@
if (options.pattern) {
input.attr('pattern', options.pattern);
}
else {
if(options.inputType === 'date') {
// Add the ISO-8601 short date format as a fallback for browsers without native type="date" support
input.attr('pattern', '\d{4}-\d{2}-\d{2}');
}
else if(options.inputType === 'time') {
// Add an HH:MM pattern as a fallback for browsers without native type="time" support
input.attr('pattern', '\d{2}:\d{2}');
}
}

if (options.required) {
input.prop({ 'required': true });
Expand Down
2 changes: 1 addition & 1 deletion dist/bootbox.min.js

Large diffs are not rendered by default.

0 comments on commit 686963a

Please sign in to comment.