Skip to content

Commit 540b16b

Browse files
javier-godoypaodb
authored andcommitted
fix: increment day when button is clicked before input focus
1 parent b376b81 commit 540b16b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/resources/META-INF/frontend/fc-date-picker/fc-date-picker.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export class FcDatePicker extends DatePicker {
6969
}
7070
}
7171
};
72+
73+
this.inputElement.addEventListener('focus', ()=>this.__focused=true);
7274
}
7375

7476
refreshAll() {
@@ -156,7 +158,17 @@ export class FcDatePicker extends DatePicker {
156158
.replaceAll('1','M')
157159
.replaceAll('2','D')
158160
.replaceAll('3','Y');
159-
const part = format.replace(new RegExp(`^([DMY]+[^DMY]){${index}}`),'')[0];
161+
let part;
162+
if (this.__focused) {
163+
part = format.replace(new RegExp(`^([DMY]+[^DMY]){${index}}`),'')[0];
164+
} else {
165+
part = 'D';
166+
// find the index where D start
167+
index = 0;
168+
for (let i=0;i<format.length && format[i]!=part;i++) {
169+
if (!format[i].match(/[0-9]/)) index++;
170+
}
171+
}
160172

161173
const incrementComponent = (date, part, delta) => {
162174
// Adjusts the specified component (year, month, or day) by the given delta,

0 commit comments

Comments
 (0)