Require key, instrument, tuning

This commit is contained in:
Ian Keane 2026-06-11 17:12:05 -04:00
parent eaf89d1d89
commit 52eb0f6189
3 changed files with 39 additions and 1 deletions

35
app.js
View file

@ -504,6 +504,7 @@ function openAdd() {
editingTuneId = null;
editingEntryId = null;
editingOriginalRefIds = [];
setTuneError('');
$('modal-title').textContent = 'Add tune';
tuneForm.reset();
refsList.innerHTML = '';
@ -659,11 +660,43 @@ function addRefRow(link = '', site = '', refId = null, siteId = null, initialMus
// ── Save ──────────────────────────────────────────────────────
$('btn-save-tune').addEventListener('click', saveTune);
$('btn-cancel').addEventListener('click', () => tuneModal.close());
$('btn-cancel').addEventListener('click', () => { setTuneError(''); tuneModal.close(); });
function setTuneError(msg) {
const el = $('tune-error');
el.textContent = msg;
el.hidden = !msg;
}
async function saveTune() {
const f = tuneForm.elements;
// Validate required fields
const keyVal = f.key.value.trim();
const tuningVal = f.inst_tuning.value.trim();
if (!keyVal) {
setTuneError('Key is required.');
f.key.focus();
return;
}
if (!instrumentSelect.value) {
setTuneError('Instrument is required.');
instrumentSelect.focus();
return;
}
if (!tuningVal) {
setTuneError('Tuning is required.');
f.inst_tuning.focus();
return;
}
if (!resolveTuningId(tuningVal)) {
setTuneError(`Tuning "${tuningVal}" not found — use + to add it first.`);
f.inst_tuning.focus();
return;
}
setTuneError('');
const tuneBody = {
name: f.name.value || null,
key: f.key.value || null,