When the company is indian then i want to set the country code +91. is this possible to set the country code in the Mobile Number field .
Here Mobile Number field is a Phone field Type.
@PRaful_9898 Please try this code
frappe.ui.form("Customer", {
refresh: function(frm){
// your company logic which country your company
if (country == "India"){
cur_frm.set_value("phone", "+91-");
}
})
3 Likes
Its worked .but when the user did not enter the mobile number then showing Error
Below is the screenshot
It’s a bigger issue if the country code is set as the default because then you must enter the mobile/phone number.
1 Like
You’re absolutely right. Thanks for pointing this out .
on
is missing and also }
closing bracket is missing.
but @PRaful_9898, you can use onload
instead of refresh
and don’t use the frm.set_value
Try the following code. I tested it and it worked for me, but I’m not sure about other scenarios. Please check it.
frappe.ui.form.on("Customer", {
onload: function(frm) {
if (frm.doc.country == "India") {
frm.doc.phone = "+91-";
}
}
});
1 Like
My workaround is to revert the value in the before_save method
before_save(frm) {
if (frm.doc.phone == '+91-') {
frm.doc.phone = '';
}
},