From 52c933c7c80a6e770617d487875ed956b319998b Mon Sep 17 00:00:00 2001 From: bordun Date: Wed, 2 Dec 2020 11:20:16 +0100 Subject: [PATCH] input: apply `decimals` number before checking the value against the `validation` expression --- CHANGELOG.md | 1 + src/client/widgets/basics/input.js | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2306e6c5..f2e3c1b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - bug fixes - editor: cloned `dropdown` and `input` widgets not opening when selected - widgets: prevent value-stateless widgets (tap buttons, clone, scripts, html and svg) from sending a value for cross-client synchronization (leads to unexpected script execution) and exclude them from state saves + - input: apply `decimals` number before checking the value against the `validation` expression ## 1.7.3 diff --git a/src/client/widgets/basics/input.js b/src/client/widgets/basics/input.js index 150e4347..d38532bc 100644 --- a/src/client/widgets/basics/input.js +++ b/src/client/widgets/basics/input.js @@ -139,7 +139,7 @@ class Input extends Canvas { setValue(v, options={} ) { - if (this.validation && !String(v).match(this.validation)) { + if (this.validation && !this.getStringValue(v).match(this.validation)) { this.input.value = this.value return } @@ -152,7 +152,7 @@ class Input extends Canvas { if (this.value === '' || this.value === null) this.value = this.getProp('default') - this.stringValue = this.getStringValue() + this.stringValue = this.getStringValue(this.value) this.batchDraw() if (options.send && !options.fromSync) this.sendValue() @@ -184,11 +184,11 @@ class Input extends Canvas { } - getStringValue() { - if (this.value === undefined) return '' - return typeof this.value != 'string' ? - JSON.stringify(deepCopy(this.value, this.decimals)).replace(/,/g, ', ') : - this.value + getStringValue(v) { + if (v === undefined) return '' + return typeof v != 'string' ? + JSON.stringify(deepCopy(v, this.decimals)).replace(/,/g, ', ') : + v } }