Hello, hope everyone is doing well!
Please, I have a code to format a field as the user types, but I don't know how to use it in a VoltMx form:
$(document).ready(function() {
$('input[name="cpf"]').on('keyup', function() {
var cpf = $(this).val().replace(/\D/g, '');
if (cpf.length == 11) {
$(this).val(cpf.substring(0, 3) + '.' + cpf.substring(3, 6) + '.' + cpf.substring(6, 9) + '-' + cpf.substring( 9, 11));
}
});
});
I have created a sample form with a text field widget called txtField.
This is the code of the controller:
-----------------------------------------
define({
onViewCreated(){
this.view.init = () => {
this.view.txtField.onTextChange = () => {
let cpf = this.view.txtField.text;
cpf = cpf.replace(/\D/g, '');
if(cpf.length === 11){
cpf = cpf.substring(0, 3) + '.' + cpf.substring(3, 6) + '.' + cpf.substring(6, 9) + '-' + cpf.substring( 9, 11);
}
this.view.txtField.text = cpf;
};
};
}
});
--------------------------------