From dbc6870be0faec7d02e7cf73a0efd6b9d7bbf263 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 26 Aug 2025 23:41:00 +0200 Subject: [PATCH] feat: format IBANs in Data field --- frappe/model/__init__.py | 2 +- frappe/public/js/frappe/form/controls/data.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frappe/model/__init__.py b/frappe/model/__init__.py index 994624608c..e3669f56a3 100644 --- a/frappe/model/__init__.py +++ b/frappe/model/__init__.py @@ -77,7 +77,7 @@ display_fieldtypes = ( numeric_fieldtypes = ("Currency", "Int", "Long Int", "Float", "Percent", "Check") -data_field_options = ("Email", "Name", "Phone", "URL", "Barcode") +data_field_options = ("Email", "Name", "Phone", "URL", "Barcode", "IBAN") default_fields = ( "doctype", diff --git a/frappe/public/js/frappe/form/controls/data.js b/frappe/public/js/frappe/form/controls/data.js index 24690cc073..d80c7467cf 100644 --- a/frappe/public/js/frappe/form/controls/data.js +++ b/frappe/public/js/frappe/form/controls/data.js @@ -73,6 +73,9 @@ frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlInp if (this.df.options == "Barcode") { this.setup_barcode_field(); } + if (this.df.options == "IBAN") { + this.setup_iban_field(); + } } setup_url_field() { @@ -118,6 +121,12 @@ frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlInp }); } + setup_iban_field() { + this.$input.on("blur", () => { + this.set_formatted_input(this.get_input_value()); + }); + } + setup_copy_button() { if (this.df.with_copy_button) { this.$wrapper @@ -257,8 +266,17 @@ frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlInp return this.$input ? this.$input.val() : undefined; } format_for_input(val) { + if (this.df.options == "IBAN" && val) { + return val.replaceAll(" ", "").replace(/(.{4})(?=.)/g, "$1 "); + } return val == null ? "" : val; } + parse(value) { + if (this.df.options == "IBAN" && value) { + return value.replaceAll(" ", ""); + } + return value; + } validate(v) { if (!v) { return "";