Skip to content

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

@toninhonunes

Description

@toninhonunes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions