Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
toninhonunes opened this issue Nov 6, 2020 · 1 comment
Open

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

toninhonunes opened this issue Nov 6, 2020 · 1 comment

Comments

@toninhonunes
Copy link

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 + '-TOTAL_FORMS').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! 🍺

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

@andre-mn
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants