Динамическое добавление/удаление элементов в сетке начальной загрузки с помощью jQuery работает нормально, но как мы можем предотвратить удаление первого элемента? Также я хочу добавить некоторые ограничения на добавление элементов. Можете ли вы мне помочь с этим? Я обновил демо-версию здесь
$(function() {
// Remove button click
$(document).on(
'click',
'[data-role="appendRow"] > .form-inline [data-role="remove"]',
function(e) {
e.preventDefault();
$(this).closest('.form-row').remove();
}
);
// Add button click
$(document).on(
'click',
'[data-role="appendRow"] > .form-row [data-role="add"]',
function(e) {
e.preventDefault();
var container = $(this).closest('[data-role="appendRow"]');
new_field_group = container.children().filter('.form-row:first-child').clone();
container.append(new_field_group);
}
);
});
Подробнее здесь: https://stackoverflow.com/questions/785 ... -the-first
Мобильная версия