Исправлено отображение шаблона пустой формы в formset

Проблема:
- Над секцией "Товары в заказе" отображался странный dropdown
- Шаблон формы использовал <div style="display: none;"> вместо <template>

Исправление:
- Заменен <div id="empty-form-template" style="display: none;"> на <template>
- Добавлен id для select в шаблоне
- Обновлен JavaScript для работы с HTML5 <template> element
- Используется template.content для правильного клонирования

Теперь шаблон полностью невидим и не влияет на layout

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-08 22:53:41 +03:00
parent 809d5a127a
commit 024edea9f1

View File

@@ -256,7 +256,7 @@
</div> </div>
<!-- Скрытый шаблон для новых форм --> <!-- Скрытый шаблон для новых форм -->
<div id="empty-form-template" style="display: none;"> <template id="empty-form-template">
<div class="order-item-form border rounded p-3 mb-3" data-form-index="__prefix__"> <div class="order-item-form border rounded p-3 mb-3" data-form-index="__prefix__">
<input type="hidden" name="items-__prefix__-id" id="id_items-__prefix__-id"> <input type="hidden" name="items-__prefix__-id" id="id_items-__prefix__-id">
<input type="hidden" name="items-__prefix__-product" id="id_items-__prefix__-product"> <input type="hidden" name="items-__prefix__-product" id="id_items-__prefix__-product">
@@ -267,7 +267,7 @@
<div class="col-md-5"> <div class="col-md-5">
<div class="mb-2"> <div class="mb-2">
<label class="form-label">Товар или комплект</label> <label class="form-label">Товар или комплект</label>
<select class="form-select select2-order-item" data-form-index="__prefix__"> <select class="form-select select2-order-item" data-form-index="__prefix__" id="id_items-__prefix__-select">
<option value=""></option> <option value=""></option>
</select> </select>
</div> </div>
@@ -303,7 +303,7 @@
</div> </div>
</div> </div>
</div> </div>
</div> </template>
<button type="button" class="btn btn-success" id="add-item-btn"> <button type="button" class="btn btn-success" id="add-item-btn">
<i class="bi bi-plus-circle"></i> Добавить товар <i class="bi bi-plus-circle"></i> Добавить товар
@@ -531,8 +531,9 @@ document.addEventListener('DOMContentLoaded', function() {
const formCount = parseInt(totalFormsInput.value); const formCount = parseInt(totalFormsInput.value);
// Клонируем шаблон // Клонируем шаблон
const templateContent = emptyFormTemplate.querySelector('.order-item-form'); const templateContent = emptyFormTemplate.content || emptyFormTemplate;
const newForm = templateContent.cloneNode(true); const formTemplate = templateContent.querySelector('.order-item-form');
const newForm = formTemplate.cloneNode(true);
// Заменяем __prefix__ на реальный индекс // Заменяем __prefix__ на реальный индекс
newForm.innerHTML = newForm.innerHTML.replace(/__prefix__/g, formCount); newForm.innerHTML = newForm.innerHTML.replace(/__prefix__/g, formCount);