I want to show the error message:
zone.js:192 Uncaught TypeError: this.inputCpfCnpj.mask is not a function
at MascaraCpfCnpj.onTipoPessoaAlterado (scripts.bundle.js:815)
at HTMLInputElement.dispatch (scripts.bundle.js:3)
at HTMLInputElement.y.handle (scripts.bundle.js:3)
at ZoneDelegate.invokeTask (zone.js:421)
at Zone.runTask (zone.js:188)
at ZoneTask.invokeTask [as invoke] (zone.js:495)
at invokeTask (zone.js:1536)
at HTMLInputElement.globalZoneAwareCallback (zone.js:1562)
And I would like you to know that the line of code that is issuing this error message is this here:
this.inputCpfCnpj.mask(tipoPessoaSelecionada.data('mascara'));
I'm going to start explaining what the system is doing, then I'll show you what I need to do:
See the figure below:
WhenyouclickontheradioButtomIndividualitautomaticallychangestheLabeloftheCPF/CNPJfieldtoCPFandenablesthefield,andwhenyouclickontheLegalBaritwillautomaticallychangethelabeltoCNPJasyoucanseebelow:
Whodoesthisistheselinesofcode:
this.labelCpfCnpj.text(tipoPessoaSelecionada.data('documento'));this.inputCpfCnpj.removeAttr('disabled');
SeeifItypeanythinginthefieldandswitchtoanotherradioButtomitclearsthefieldautomatically:
Part1
Part2
WhenImovetotheLegalradioButtomitclearsthefieldautomatically.
WhatIwanttodoiswhentheuserclicksonthePhysicalradioButtomitautomaticallyplacesthemaskofPhysicalperson000.000.000-00
andwhentheuserclicksontheradioButtomLegal00.000.000/0000-00
wastoformatthefieldautomatically,thisisnothappeningbecausethislineofcodeishavingproblem:
this.inputCpfCnpj.mask(tipoPessoaSelecionada.data('mascara'));
ThisismyJavascriptfile:
varBrewer=Brewer||{};Brewer.MascaraCpfCnpj=(function(){functionMascaraCpfCnpj(){this.radioTipoPessoa=$('.js-radio-tipo-pessoa');this.labelCpfCnpj=$('[for=cpfOuCnpj]');this.inputCpfCnpj=$('#cpfOuCnpj');}MascaraCpfCnpj.prototype.iniciar=function(){this.radioTipoPessoa.on('change',onTipoPessoaAlterado.bind(this));}functiononTipoPessoaAlterado(evento){vartipoPessoaSelecionada=$(evento.currentTarget);this.labelCpfCnpj.text(tipoPessoaSelecionada.data('documento'));this.inputCpfCnpj.val('');this.inputCpfCnpj.removeAttr('disabled');}returnMascaraCpfCnpj;}());$(function(){varmascaraCpfCnpj=newBrewer.MascaraCpfCnpj();mascaraCpfCnpj.iniciar();});
Andthat'sthesnippetofmypagecode:
Typeperson Physics JuridicaCPF/CNPJ
AndIdebuggedthemascaracodeanditworked,note:
With this code:
function onTipoPessoaAlterado(evento) {
var tipoPessoaSelecionada = $(evento.currentTarget);
this.labelCpfCnpj.text(tipoPessoaSelecionada.data('documento'));
this.inputCpfCnpj.val(' ');
this.inputCpfCnpj.removeAttr('disabled');
console.log('mascara', tipoPessoaSelecionada.data('mascara'));
}
I'm open to suggestions