From 54bf159d9accfaf37bc3bcaf4ffe285cf820ef22 Mon Sep 17 00:00:00 2001 From: akkshaylaw Date: Thu, 30 Jul 2020 16:30:05 +0530 Subject: [PATCH] Added trailing zeroes when focus is changed in decomal mode. --- src/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 5f0b888..6fe8f47 100644 --- a/src/index.js +++ b/src/index.js @@ -29,6 +29,12 @@ } } + function add_trailing_zeroes() { + if (this.value && this.value.indexOf('.') === -1) { + this.value += '.00'; + } + } + function exec_integer(event) { this.value = this.value.replace(/[^\d].+/, ""); if (event.which < 48 || event.which > 57) { @@ -61,7 +67,7 @@ switch (filter) { case "decimal": if (tag == "input") { - element.addEventListener("blur", exec_decimal); + element.addEventListener("blur", add_trailing_zeroes); element.addEventListener("keypress", exec_decimal); element.addEventListener("keyup", exec_decimal); element.setAttribute("type", "number");