diff --git a/cypress/integration/control_float.js b/cypress/integration/control_float.js index e7d6b398f1..08b71eb870 100644 --- a/cypress/integration/control_float.js +++ b/cypress/integration/control_float.js @@ -32,10 +32,13 @@ context("Control Float", () => { cy.wait(200); cy.fill_field("float_number", d.input, "Float").blur(); cy.get_field("float_number", "Float").should("have.value", d.blur_expected); - + cy.wait(100); cy.get_field("float_number", "Float").focus(); + cy.wait(100); cy.get_field("float_number", "Float").blur(); + cy.wait(100); cy.get_field("float_number", "Float").focus(); + cy.wait(100); cy.get_field("float_number", "Float").should("have.value", d.focus_expected); }); }); @@ -49,17 +52,17 @@ context("Control Float", () => { { input: "364.87,334", blur_expected: "36.487,334", - focus_expected: "36487.334", + focus_expected: "36.487,334", }, { - input: "36487,334", - blur_expected: "36.487,334", - focus_expected: "36487.334", + input: "36487,335", + blur_expected: "36.487,335", + focus_expected: "36.487,335", }, { - input: "100", - blur_expected: "100,000", - focus_expected: "100", + input: "2*(2+47)+1,5+1", + blur_expected: "100,500", + focus_expected: "100,500", }, ], }, @@ -67,19 +70,19 @@ context("Control Float", () => { number_format: "#,###.##", values: [ { - input: "364,87.334", - blur_expected: "36,487.334", - focus_expected: "36487.334", + input: "464,87.334", + blur_expected: "46,487.334", + focus_expected: "46,487.334", }, { - input: "36487.334", - blur_expected: "36,487.334", - focus_expected: "36487.334", + input: "46487.335", + blur_expected: "46,487.335", + focus_expected: "46,487.335", }, { - input: "100", - blur_expected: "100.000", - focus_expected: "100", + input: "3*(2+47)+1.5+1", + blur_expected: "149.500", + focus_expected: "149.500", }, ], }, @@ -90,13 +93,13 @@ context("Control Float", () => { { input: "12.345", blur_expected: "12.345,000", - focus_expected: "12345", + focus_expected: "12.345,000", }, { // parseFloat would reduce 12,340 to 12,34 if this string was ever to be parsed input: "12.340", blur_expected: "12.340,000", - focus_expected: "12340", + focus_expected: "12.340,000", }, ], }, diff --git a/frappe/public/js/frappe/form/controls/float.js b/frappe/public/js/frappe/form/controls/float.js index 0066020a8f..5cb674d2f8 100644 --- a/frappe/public/js/frappe/form/controls/float.js +++ b/frappe/public/js/frappe/form/controls/float.js @@ -1,17 +1,4 @@ frappe.ui.form.ControlFloat = class ControlFloat extends frappe.ui.form.ControlInt { - make_input() { - super.make_input(); - const change_handler = (e) => { - if (this.change) this.change(e); - else { - let value = this.get_input_value(); - this.parse_validate_and_set_in_model(value, e); - this.refresh(); - } - }; - // convert to number format on focusout since focus converts it to flt. - this.$input.on("focusout", change_handler); - } parse(value) { value = this.eval_expression(value); return isNaN(parseFloat(value)) ? null : flt(value, this.get_precision()); diff --git a/frappe/public/js/frappe/form/controls/int.js b/frappe/public/js/frappe/form/controls/int.js index 42b243062d..ffd3fe5fc3 100644 --- a/frappe/public/js/frappe/form/controls/int.js +++ b/frappe/public/js/frappe/form/controls/int.js @@ -13,7 +13,6 @@ frappe.ui.form.ControlInt = class ControlInt extends frappe.ui.form.ControlData .on("focus", function () { setTimeout(function () { if (!document.activeElement) return; - document.activeElement.value = me.validate(document.activeElement.value); document.activeElement.select(); }, 100); return false; @@ -24,10 +23,19 @@ frappe.ui.form.ControlInt = class ControlInt extends frappe.ui.form.ControlData } eval_expression(value) { if (typeof value === "string") { - if (value.match(/^[0-9+\-/* ]+$/)) { + const parsed_components = value.match(/[^\d.,]+|[\d.,]+/g); + var parsed_value = value; + if (parsed_components !== null) { + parsed_value = parsed_components + .map((v) => { + return isNaN(parseFloat(v)) ? v : flt(v); + }) + .join(""); + } + if (parsed_value.match(/^[0-9+\-/*.() ]+$/)) { // If it is a string containing operators try { - return eval(value); + return eval(parsed_value); } catch (e) { // bad expression return value; diff --git a/frappe/templates/base.html b/frappe/templates/base.html index 55065924de..6f4c3a8ad7 100644 --- a/frappe/templates/base.html +++ b/frappe/templates/base.html @@ -1,6 +1,6 @@ - + diff --git a/frappe/website/utils.py b/frappe/website/utils.py index f5579d9adb..872b790cfc 100644 --- a/frappe/website/utils.py +++ b/frappe/website/utils.py @@ -166,7 +166,7 @@ def get_home_page_via_hooks(): def get_boot_data(): return { - "lang": "en", + "lang": frappe.local.lang or "en", "sysdefaults": { "float_precision": cint(frappe.get_system_settings("float_precision")) or 3, "date_format": frappe.get_system_settings("date_format") or "yyyy-mm-dd",