Skip to content

Commit

Permalink
Set autocomplete off to all widget elements that can have autocomplet…
Browse files Browse the repository at this point in the history
…e attribute to prevent autofilled with another element autocomplete
  • Loading branch information
gushil committed Aug 6, 2024
1 parent c0c515b commit e84e16c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/enketo-core/src/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ class Widget {
this.question = element.closest('.question');
this._props = this._getProps();

// Based on https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
// set autocomplete off for all elements that can have autocomplete attribute
if (
(this.element.nodeName.toLowerCase() === 'input' &&
['text', 'number'].includes(
this.element.getAttribute('type')
)) ||
this.element.nodeName.toLowerCase() === 'textarea' ||
this.element.nodeName.toLowerCase() === 'select'
) {
this.element.setAttribute('autocomplete', 'off');
}

// Some widgets (e.g. ImageMap) initialize asynchronously and init returns a promise.
return this._init() || this;
}
Expand Down

0 comments on commit e84e16c

Please sign in to comment.