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 e5d3ed0
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' &&

Check failure on line 43 in packages/enketo-core/src/js/widget.js

View workflow job for this annotation

GitHub Actions / lint (20.12.2)

Expected '===' and instead saw '=='
['text', 'number'].includes(
this.element.getAttribute('type')
)) ||
this.element.nodeName.toLowerCase() == 'textarea' ||

Check failure on line 47 in packages/enketo-core/src/js/widget.js

View workflow job for this annotation

GitHub Actions / lint (20.12.2)

Expected '===' and instead saw '=='
this.element.nodeName.toLowerCase() == 'select'

Check failure on line 48 in packages/enketo-core/src/js/widget.js

View workflow job for this annotation

GitHub Actions / lint (20.12.2)

Expected '===' and instead saw '=='
) {
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 e5d3ed0

Please sign in to comment.