From 2651eb3da14943be0ccb6455e10b41a2ed9e9972 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Fri, 4 Dec 2020 12:57:54 +0100 Subject: [PATCH] checking negatives --- .../remix-ide/src/app/tabs/runTab/settings.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/runTab/settings.js b/apps/remix-ide/src/app/tabs/runTab/settings.js index a10aac0fa4..9a54f15eff 100644 --- a/apps/remix-ide/src/app/tabs/runTab/settings.js +++ b/apps/remix-ide/src/app/tabs/runTab/settings.js @@ -53,16 +53,26 @@ class SettingsUI { }) } + validateInput (e) { + console.log('start value = ', this.el.querySelector('#value').value) + console.log("e = ", e) + if (!helper.isNumeric(e.key)) { + console.log("e.data = ", e.key) + e.preventDefault() + e.stopImmediatePropagation() + } + } + validateValue () { const valueEl = this.el.querySelector('#value') valueEl.value = parseInt(valueEl.value) // assign 0 if given value is // - empty // - not valid (for ex 4345-54) - // - contains only '0's (for ex 00..0) + // - contains only '0's (for ex 0000) if (!valueEl.value) valueEl.value = 0 - // if giveen value is negative, ignore '-' - if (valueEl.value < 0) valueEl.value = Math.abs(valueEl.value) + // if giveen value is negative(possible with copy-pasting) set to 0 + if (valueEl.value < 0) valueEl.value = 0 } render () { @@ -132,11 +142,14 @@ class SettingsUI { this.validateInputKey(e)} onchange=${() => this.validateValue()} >