select

Better select widgets in vanilla javascript.  https://p.ce9e.org/select/demo/
git clone https://git.ce9e.org/select.git

commit
497e43296f872fc16ebb8f80cccd7c18ced29ffb
parent
8559738c7f50629a66dffbd99b358efc1b39f67e
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2021-03-25 14:59
validate temporary value

Diffstat

M select.js 12 +++++++++++-

1 files changed, 11 insertions, 1 deletions


diff --git a/select.js b/select.js

@@ -156,6 +156,14 @@ class Select {
  156   156 		this.updateValue();
  157   157 	}
  158   158 
   -1   159 	hasTemporaryValue() {
   -1   160 		if (this.original.multiple) {
   -1   161 			return this.input.value;
   -1   162 		} else {
   -1   163 			return this.input.value !== this.original.selectedOptions[0].label;
   -1   164 		}
   -1   165 	}
   -1   166 
  159   167 	onkeydown(event) {
  160   168 		if (this.focus !== -1) {
  161   169 			if (event.keyCode === KEYS.DOWN) {
@@ -212,7 +220,9 @@ class Select {
  212   220 			if (this.indexMap.length) {
  213   221 				this.setValue(this.indexMap[this.focus]);
  214   222 			}
  215    -1 			if (!this.original.checkValidity()) {
   -1   223 			if (this.hasTemporaryValue()) {
   -1   224 				this.input.setCustomValidity('temporary value');
   -1   225 			} else if (!this.original.checkValidity()) {
  216   226 				this.input.setCustomValidity(this.original.validationMessage);
  217   227 			}
  218   228 			this.close();