Closes #3810: Preserve slug value when editing existing objects

This commit is contained in:
Jeremy Stretch
2020-02-19 13:53:11 -05:00
parent f05c7be394
commit 7a53e24f97
4 changed files with 28 additions and 5 deletions

View File

@@ -42,17 +42,23 @@ $(document).ready(function() {
return s.substring(0, num_chars); // Trim to first num_chars chars
}
var slug_field = $('#id_slug');
slug_field.change(function() {
$(this).attr('_changed', true);
});
if (slug_field) {
var slug_source = $('#id_' + slug_field.attr('slug-source'));
var slug_length = slug_field.attr('maxlength');
if (slug_field[0].value) {
slug_field.attr('_changed', true);
}
slug_field.change(function() {
$(this).attr('_changed', true);
});
slug_source.on('keyup change', function() {
if (slug_field && !slug_field.attr('_changed')) {
slug_field.val(slugify($(this).val(), (slug_length ? slug_length : 50)));
}
})
});
$('button.reslugify').click(function() {
slug_field.val(slugify(slug_source.val(), (slug_length ? slug_length : 50)));
});
}
// Bulk edit nullification