Custom/Server Script to change filed value to Title Case on save

Please help me with Custom/server Script to change filed value to Title Case on save, no matter user type in Uppercase or Lowercase.

Thanks in Advance.


This is to change Item name. You can use this code

function toTitleCase(str) {
    return str.replace(/\w\S*/g, function(txt) {
        return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();

frappe.ui.form.on('Item', {
    before_save(frm) {
        frm.doc.item_name = toTitleCase(frm.doc.item_name);
1 Like

Thanks @ErpnextRaja, for a prompt reply.
It’s working fine. This will also help to others.

I am looking at this. All Character Capital. and it works.

frappe.ui.form.on('Customer', {
    refresh: function(frm) {
        // Assuming you want to convert the 'description' field to uppercase
        cur_frm.fields_dict['customer_name'].df.onchange = function() {
            cur_frm.doc.customer_name = cur_frm.doc.customer_name.toUpperCase();

Admin can close this Thread.