From 1f3d363b179312666d86d809f813c4a26c18b12c Mon Sep 17 00:00:00 2001 From: jeremy-seipelt Date: Tue, 5 Nov 2019 17:56:59 +0100 Subject: [PATCH] add jovans code snippet and fill native select with the form id --- BrickSelect/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/BrickSelect/index.js b/BrickSelect/index.js index 83c75d0..0206fc6 100644 --- a/BrickSelect/index.js +++ b/BrickSelect/index.js @@ -113,6 +113,10 @@ const BrickSelect = { this._processOptions(); this._nativeSelect.required = this.hasAttribute('required'); + + if (!!this.getAttribute('form')) { + this._nativeSelect.setAttribute("form",this.getAttribute('form')); + } this.addEventListener('click', this._onSelectOpened.bind(this)); this.addEventListener('change', this._onSelectionChanged.bind(this)); @@ -225,9 +229,12 @@ const BrickSelect = { event.preventDefault(); - if (event.target.form.querySelector(':invalid') !== event.target) { + const firstInvalidInput = Array.from(event.target.form.elements) + .find(element => element.matches(':invalid')); + + if (firstInvalidInput !== event.target) { return; - } + } event.target.parentElement.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'smooth' }); },