I'm using AutoNumeric.js (v4.6.0) in my project and I have a form that dynamically creates a price field. When the page is loaded, the first input that comes by default works fine, but the ones that are created automatically afterwards do not work unfortunately. How can i solve this problem ? Thank you from now.
$(function () {
new AutoNumeric(".autonumber", { currencySymbol : '$' });
$(document).on('click', '#addSpending', function () {
var newSpending =
'<div class="row g-1">' +
'<div class="col-md-12">' +
'<input type="text" class="form-control autonumber" name="amount[]" required>' +
'</div>' +
'</div>';
$('#spendings').append(newSpending);
});
});
You need to use the
AutoNumeric
instance after you append the field to the form like so:Here's also a sandbox