datatracker/static/facelift/js/ipr-edit.js
Ole Laursen 1124d6d018 Summary: Port the remaining parts of the IPR form to Bootstrap, and fix
some bugs in the port
 - Legacy-Id: 8900
2015-01-23 16:47:22 +00:00

57 lines
1.8 KiB
JavaScript

$(document).ready(function() {
var form = $(".ipr-form");
form.find("input[required],select[required],textarea[required]").closest(".form-group").find("label").addClass("required");
var template = form.find('.draft-row.template');
var templateData = template.clone();
$('.draft-add-row').click(function() {
var el = template.clone(true);
var totalField = $('#id_iprdocrel_set-TOTAL_FORMS');
var total = +totalField.val();
el.find(':input').each(function() {
var name = $(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-');
var id = 'id_' + name;
$(this).attr({'name': name, 'id': id}).val('');
});
el.find('label').each(function() {
var newFor = $(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-');
$(this).attr('for', newFor);
});
++total;
totalField.val(total);
template.before(el);
el.removeClass("template");
el.find(".select2-field").each(function () {
setupSelect2Field($(this));
});
});
function updateRevisions() {
var selectbox = $(this).find('[name$="document"]');
if (selectbox.val()) {
var name = selectbox.select2("data").text;
if (name.toLowerCase().substring(0, 3) == "rfc")
$(this).find('[name$=revisions]').val("").hide();
else
$(this).find('[name$=revisions]').show();
}
}
form.on("change", ".select2-field", function () {
$(this).closest(".draft-row").each(updateRevisions);
});
// add a little bit of delay to let the select2 box have time to do its magic
setTimeout(function () {
form.find(".draft-row").each(updateRevisions);
}, 10);
});