feat: format IBANs in Data field

This commit is contained in:
barredterra 2025-08-26 23:41:00 +02:00
parent 5d675e8aa7
commit dbc6870be0
2 changed files with 19 additions and 1 deletions

View file

@ -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",

View file

@ -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 "";