igorescobar / jQuery-Mask-Plugin

A jQuery Plugin to make masks on form fields and HTML elements.
http://igorescobar.github.io/jQuery-Mask-Plugin/
Other
4.77k stars 1.42k forks source link

Property data-mask does not work with dynamic fields ! #760

Open toninhonunes opened 3 years ago

toninhonunes commented 3 years ago

Have you take a look into our docs?

https://igorescobar.github.io/jQuery-Mask-Plugin/ Yes

Make sure your read this before opening a new issue:

https://github.com/igorescobar/jQuery-Mask-Plugin#problems-or-questions Yes. I did.

Device

Computer/PC

Browser (and version)?

Google Chrome 86.0.4240.183

Functional jsfiddle exemplifying your problem:

You can use this one as exemple: http://jsfiddle.net/igorescobar/6pco4om7/

Describe de problem depth:

Hi,

I have a form with 4 fields and a button. When I click on button to add a clone that fields. I have a field with data-mask='00/00/0000'. When the form is loaded and ready that mask works very well. But when I click in the button to Add cloned that fields but the data-mask does not works more. Are there a way activate that?

I have that function to clone. I tried call .mask() but it does not have effect. The new Field doest not receive the mask input.

function cloneMore(selector, prefix) { var newElement = $(selector).clone(true); var total = $('#id_' + prefix + '-TOTALFORMS').val(); newElement.find(':input:not([type=button]):not([type=submit]):not([type=reset])').each(function() { var name = $(this).attr('name').replace('-' + (total-1) + '-', '-' + total + '-'); var id = 'id' + name; $(this).attr({'name': name, 'id': id}).val('').removeAttr('checked'); }); newElement.find('label').each(function() { var forValue = $(this).attr('for'); if (forValue) { forValue = forValue.replace('-' + (total-1) + '-', '-' + total + '-'); $(this).attr({'for': forValue}); } }); total++; $('#id_' + prefix + '-TOTAL_FORMS').val(total); $(selector).after(newElement); var conditionRow = $('.form-row:not(:last)'); conditionRow.find('.btn.add-form-row') .removeClass('btn-success').addClass('btn-danger') .removeClass('add-form-row').addClass('remove-form-row') .html('');

$('#id_' + prefix + '-' + (total-1) + '-codigo_dependente').val(99999);
$('#id_' + prefix + '-' + (total-1) + '-data_nascimento').val('00/00/0000');
$('#id_' + prefix + '-' + (total-1) + '-data_nascimento').mask('00/00/0000');
return false;

}

Is this plugin helping you out? Buy me a beer and cheers! :beer:

:bowtie: https://www.paypal.me/igorcescobar

andre-mn commented 1 year ago

+1, i am using html notation for the fields i am cloning, that doesn't work either