Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #944 from enketo/fix/date-month-year-autocomplete-943
Browse files Browse the repository at this point in the history
Fix: undesired autocompletion of manually entered incomplete month-ye…
  • Loading branch information
eyelidlessness authored Feb 1, 2023
2 parents fafb623 + 854efaf commit 885dde9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/widget/date/datepicker-extended.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ class DatepickerExtended extends Widget {
let value =
e.type === 'paste'
? getPasteData(e.originalEvent ?? e)
: this.value;
: this.displayedValue;

if (value.length > 0) {
// Note: types.date.convert considers numbers to be a number of days since the epoch
// as this is what the XPath evaluator may return.
// For user-entered input, we want to consider a Number value to be incorrect, expect for year input.
// For user-entered input, we want to consider a Number value to be incorrect, except for year input.
if (isNumber(value) && settings.format !== 'yyyy') {
convertedValue = '';
} else {
Expand Down
11 changes: 11 additions & 0 deletions test/spec/widget.date.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ describe('datepicker widget', () => {

fakeInput.dispatchEvent(event);

expect(input.value).to.equal('');
});
it(`sets empty string when user enters year and appearance is ${desc}`, () => {
const input = initForm(form).element;
const fakeInput = input
.closest('.question')
.querySelector('.widget input');

fakeInput.value = '2012';
fakeInput.dispatchEvent(new Event('change'));

expect(input.value).to.equal('');
});
});
Expand Down

0 comments on commit 885dde9

Please sign in to comment.