-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Hello there,
i like this widget very much but have been struggling to implement in a dynamic formset.
When i add a new form to formset, jquery just clone the row corresponding to form fields, cleans it, and gives new ids. But it doesn't copy information about widgets.
my code is as below:
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')
if(name) {
name = 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});
}
});
newElement.find('.vDateField').each(function() {
// Remove the cloned spam element: it links to an incorrect calendar
$(this).parent().find('.datetimeshortcuts').remove();
// DateTimeShortcuts is defined in DateTimeShortcuts.js in the Django admin media
DateTimeShortcuts.addCalendar(this);
});
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-new')
.html('-');
return false;
}
as you can see above, i had the same problem with AdminDateWidget, and what i did is to remove it first and add it back. so my question is how i could do for django-popup-view-field?
many thanks
regards,
Jun