diff --git a/frappe/model/base_document.py b/frappe/model/base_document.py index 71e829f61a..784c398030 100644 --- a/frappe/model/base_document.py +++ b/frappe/model/base_document.py @@ -769,7 +769,7 @@ class BaseDocument(object): # data_field options defined in frappe.model.data_field_options for phone_field in self.meta.get_phone_fields(): phone = self.get(phone_field.fieldname) - frappe.utils.validate_phone_number_with_isd(phone, phone_field.fieldname, throw=True) + frappe.utils.validate_phone_number_with_country_code(phone, phone_field.fieldname) for data_field in self.meta.get_data_fields(): data = self.get(data_field.fieldname) diff --git a/frappe/public/js/frappe/form/controls/phone.js b/frappe/public/js/frappe/form/controls/phone.js index 92abd6e20c..d67b449ac8 100644 --- a/frappe/public/js/frappe/form/controls/phone.js +++ b/frappe/public/js/frappe/form/controls/phone.js @@ -5,16 +5,28 @@ frappe.ui.form.ControlPhone = class ControlPhone extends frappe.ui.form.ControlD make_input() { super.make_input(); - this.make_icon_input(); + this.setup_country_code_picker(); this.input_events(); } input_events() { + this.$input.keydown((e) => { + const key_code = e.keyCode; + if ([frappe.ui.keyCode.BACKSPACE].includes(key_code)) { + if (this.$input.val().length == 0) { + this.country_code_picker.reset(); + } + } + }); + // Replaces code when selected and removes previously selected. - this.picker.on_change = (country) => { + this.country_code_picker.on_change = (country) => { + if (!country) { + return this.reset_inputx(); + } const country_code = frappe.boot.country_codes[country].code; const country_isd = frappe.boot.country_codes[country].isd; - this.change_flag(country_code); + this.set_flag(country_code); this.$icon = this.selected_icon.find('svg'); this.$flag = this.selected_icon.find('img'); @@ -32,7 +44,10 @@ frappe.ui.form.ControlPhone = class ControlPhone extends frappe.ui.form.ControlD if (this.$input.val()) { this.set_value(this.get_country(country) +'-'+ this.$input.val()); } - this.change_padding(); + this.update_padding(); + // hide popover and focus input + this.$wrapper.popover('hide'); + this.$input.focus(); }; this.$wrapper.find('.selected-phone').on('click', (e) => { @@ -50,9 +65,9 @@ frappe.ui.form.ControlPhone = class ControlPhone extends frappe.ui.form.ControlD }); } - make_icon_input() { + setup_country_code_picker() { let picker_wrapper = $('