Skip to content

Commit b9c6fa3

Browse files
barshat7ci-build
authored andcommitted
datepicker timezone issue on view layer fixed (#1168)
* datepicker timezone issue on view layer fixed datepicker timezone issue on view layer fixed datepicker timezone issue on view layer fixed * datepicker fix test case
1 parent 05f1e31 commit b9c6fa3

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/clientlibs/site/js/datepickerview.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@
9999
this.widgetObject.setValue(e.target.value);
100100
this.setActive();
101101
}, this.getWidget());
102+
this.widgetObject.addEventListener('input', (e) => {
103+
if( e.target.value === '') {
104+
// clear the value if user manually empties the value in date input box
105+
this._model.value = "";
106+
}
107+
}, this.getWidget());
102108
} else {
103109
if (this.widget.value !== '') {
104110
this._model.value = this.widget.value;

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/clientlibs/site/js/datepickerwidget.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,9 @@ if (typeof window.DatePickerWidget === 'undefined') {
11601160
setValue(value) {
11611161
let currDate = new Date(value);
11621162

1163+
const timezoneOffset = currDate.getTimezoneOffset();
1164+
currDate.setMinutes(currDate.getMinutes() + timezoneOffset);
1165+
11631166
if (!isNaN(currDate) && value != null) {
11641167
//in case the value is directly updated from the field without using calendar widget
11651168
this.selectedMonth = currDate.getMonth();
@@ -1193,6 +1196,9 @@ if (typeof window.DatePickerWidget === 'undefined') {
11931196
case 'focus':
11941197
handler(e);
11951198
break;
1199+
case 'input':
1200+
handler(e);
1201+
break;
11961202

11971203
}
11981204
});

ui.tests/test-module/specs/datepicker/datepicker.runtime.spec.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ describe("Form Runtime with Date Picker", () => {
6767
cy.get('input')
6868
.should(passDisabledAttributeCheck, 'disabled');
6969
cy.get('input').should(passReadOnlyAttributeCheck, 'readonly');
70-
cy.get('input').should('have.value', value)
70+
cy.get('input').invoke('val').then(inputVal => {
71+
const viewDate = new Date(inputVal);
72+
const stateDate = new Date(value);
73+
if (!isNaN(viewDate) && !isNaN(stateDate)) {
74+
// Default date could be in different format, we need to compare the intrinsic value of the date
75+
expect(viewDate.getTime()).to.equal(stateDate.getTime());
76+
} else {
77+
expect(inputVal).to.equal(value)
78+
}
79+
})
7180
})
7281
}
7382

@@ -288,4 +297,21 @@ describe("Form Runtime with Date Picker", () => {
288297
cy.get(`#${datePicker8}`).find(".cmp-adaptiveform-datepicker__calendar-icon").should('have.css', 'display', 'block');
289298
})
290299
});
300+
301+
it("Value selected from calendar widget should match the value set in model", () => {
302+
const [datePicker7, datePicker7FieldView] = Object.entries(formContainer._fields)[6];
303+
let model = datePicker7FieldView.getModel();
304+
const date = '2023-08-10';
305+
cy.get(`#${datePicker7}`).find("input").clear().type(date).blur().then(x => {
306+
expect(model.getState().value).to.equal(date);
307+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").should("be.visible").click().then(() => {
308+
cy.get("#li-day-3").should("be.visible").click(); // clicking on the 2nd day of the month of October 2023
309+
cy.get(`#${datePicker7}`).find("input").blur().should("have.value","Wednesday, 2 August, 2023")
310+
.then(() => {
311+
expect(datePicker7FieldView.getModel().getState().value).to.equal('2023-08-02')
312+
})
313+
314+
});
315+
})
316+
});
291317
})

0 commit comments

Comments
 (0)