From e5d3ed0c56e54d5c87b76ab8f0e602cc678c9e34 Mon Sep 17 00:00:00 2001 From: Agus Hilman Date: Tue, 6 Aug 2024 17:39:59 +0700 Subject: [PATCH] Set autocomplete off to all widget elements that can have autocomplete attribute to prevent autofilled with another element autocomplete --- packages/enketo-core/src/js/widget.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/enketo-core/src/js/widget.js b/packages/enketo-core/src/js/widget.js index b41cdc94..5a415162 100644 --- a/packages/enketo-core/src/js/widget.js +++ b/packages/enketo-core/src/js/widget.js @@ -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; }