fix: preserve independence for each kitten

This commit is contained in:
nyan404 committed 2026-08-25 21:36:03 +03:00
1 parent 7018bc0398
commit fa61d11912
8 files changed
+74 -74

No files matched your search

+8 -13
View File
@@ -96,9 +96,9 @@
<label>Начало<input name="start" type="time" value="11:00" required></label>
<label>Конец<input name="end" type="time" value="11:20" required></label>
<label>Имя сопровождающего<input name="escort_name" required></label>
<label>ID сопровождающего<input name="escort_id" type="number" min="1" required></label>
<label>ID сопровождающего<input name="escort_id" type="text" inputmode="numeric" pattern="[0-9]+" required></label>
<label>Имя котёнка<input name="kitten_name" required></label>
<label>ID котёнка<input name="kitten_id" type="number" min="1" required></label>
<label>ID котёнка<input name="kitten_id" type="text" inputmode="numeric" pattern="[0-9]+" required></label>
<label>Котёнок<select name="kitten_independence"><option value="самостоятельно">сам / самостоятельный</option><option value="несамостоятельно">несам / несамостоятельный</option></select><span class="muted status-help" id="statusHelp">Для ЛУ можно указать не более одного несамостоятельного котёнка.</span></label>
<div class="wide extra-kittens">
<label>Дополнительные котята <span class="muted">(общие баллы не суммируются; 2-й ×1,5, следующие ×1,15)</span></label>
@@ -248,7 +248,7 @@
function addExtraKitten(values = {}) {
const row = document.createElement('div'); row.className = 'extra-kitten';
row.innerHTML = `<input data-extra="name" placeholder="Имя котёнка" required>
<input data-extra="id" type="number" min="1" placeholder="ID" required>
<input data-extra="id" type="text" inputmode="numeric" pattern="[0-9]+" placeholder="ID" required>
<select data-extra="independence"><option value="самостоятельно">сам / самостоятельный</option><option value="несамостоятельно">несам / несамостоятельный</option></select>
<button type="button" data-remove>Удалить</button>`;
row.querySelector('[data-extra="name"]').value = values.name || '';
@@ -261,23 +261,18 @@
document.querySelector('#addKitten').addEventListener('click', () => addExtraKitten());
// Returns all independence controls participating in the current coaching form.
function statusFields() { return [document.querySelector('#coaching [name="kitten_independence"]'), ...extraKittens.querySelectorAll('[data-extra="independence"]')]; }
// Enables or locks independence controls according to the selected skill.
// Keeps every kitten's independence selection available for the chosen skill.
function updateStatusRules(event) {
const fields = statusFields();
const isZu = document.querySelector('#coaching [name="skill"]').value === 'ЗУ';
if (isZu) {
fields.forEach(field => { field.value = 'самостоятельно'; field.disabled = true; });
statusHelp.textContent = 'Для ЗУ все котята должны быть самостоятельными.';
} else {
fields.forEach(field => { field.disabled = false; });
statusHelp.textContent = 'Для ЛУ можно указать не более одного несамостоятельного котёнка.';
}
fields.forEach(field => { field.disabled = false; });
statusHelp.textContent = document.querySelector('#coaching [name="skill"]').value === 'ЛУ'
? 'Для ЛУ можно указать не более одного несамостоятельного котёнка.'
: 'Укажите самостоятельность каждого котёнка отдельно.';
}
// Returns a user-facing validation error when kitten statuses conflict.
function validateStatusRules() {
const fields = statusFields();
const skill = document.querySelector('#coaching [name="skill"]').value;
if (skill === 'ЗУ' && new Set(fields.map(field => field.value)).size > 1) return 'Для ЗУ статус всех котят должен совпадать.';
if (skill === 'ЛУ' && fields.filter(field => field.value === 'несамостоятельно').length > 1) return 'Для ЛУ допускается только один несамостоятельный котёнок.';
return '';
}