Form is not loading get_docfield (Format input) inside JS

I`m trying to use Mask inside some input… so I did that on my doctype.js:


frappe.require("assets/erpbr/js/jquery_mask/jquery.mask.min.js");

frappe.ui.form.on('Cliente', {
	refresh: function(frm) {

	},
	onload: function (frm) {
		
        frappe.meta.get_docfield('Cliente', 'cpf').on_make = function (control) {
            $(control.input).mask('000.000.000-00');
        };

        frappe.meta.get_docfield('Cliente', 'cnpj').on_make = function (control) {
            $(control.input).mask('00.000.000/0000-00');
        };

        frappe.meta.get_docfield('Cliente', 'cep').on_make = function (control) {
            $(control.input).mask('00000-000');
        };
    }
});

Doctype form load JS corectly… but appears the function frappe.meta.get_docfield doesn’t work…

Any thoughts why doesn’t work these?

No sign of an exception for clues to the problem?

No exceptions, and nothing on Console…

If I put a console.log() inside onload: function show to me on console…so… frappe call JS correctly, and call onload function… that’s the reason I believe the problem if on get_docfield function… put console.log inside them not work.

@fellipeh did you get it working? How did you do it?

Here is my solution for CNPJ and CPF (Brazil fiscal ID) validations:

  1. Create a custom app

  2. Put both scripts in app’s public folder:

JS CPF CNPJ DV validation:
https://gist.github.com/treasuryesc/f60e96eeec86d0130c5d09ce790fcbe6

jQuery Mask Plugin
https://github.com/igorescobar/jQuery-Mask-Plugin

  1. Create a client script for Customer DocType (changing your-app to custom app name):
frappe.require('/assets/<your-app>/jquery.mask.min.js');
frappe.require('/assets/<your-app>/valid-cpfcnpj.js');

frappe.ui.form.on('Customer', {
	refresh(frm) {
        // adiciona a máscara para cpf / cnpj
        if (frm.doc.customer_type == 'Individual')
            $("input[data-fieldname='tax_id']").mask('000.000.000-00');
        else
            $("input[data-fieldname='tax_id']").mask('00.000.000/0000-00');
	},
	
    validate(frm) {
        validated = true;

        if (frm.doc.tax_id !== '' && frm.doc.tax_id !== undefined && frm.doc.tax_id !== null) {
            // conferte dígito verificador
            if (frm.doc.customer_type == 'Individual')
                validated = validate_cpf(frm.doc.tax_id);
            else
                validated = validate_cnpj(frm.doc.tax_id);
                
            if (! validated) 
                msgprint('CPF ou CNPJ inválido');
        }
    },

    customer_type(frm) {
        // caso tenha trocado de tipo (PF/PJ), altera a máscara
        if (frm.doc.customer_type == 'Individual')
            $("input[data-fieldname='tax_id']").mask('000.000.000-00');
        else
            $("input[data-fieldname='tax_id']").mask('00.000.000/0000-00');
    },
});