47e1059532
datalist only shows suggestions when typing, not on click. Switched to a <select> showing all known brands plus a 'New brand...' option that reveals a text input for entering a new brand name.
71 lines
2.3 KiB
HTML
71 lines
2.3 KiB
HTML
{% extends "base.html" %}
|
||
{% block title %}Add Batteries — Battery Tracker{% endblock %}
|
||
|
||
{% block content %}
|
||
<h1>Add Batteries</h1>
|
||
|
||
<div class="card">
|
||
<form method="post" action="{{ url_for('battery_add') }}">
|
||
<div class="form-group">
|
||
<label for="brand-select">Brand <span class="text-danger">*</span></label>
|
||
<select id="brand-select" onchange="brandSelectChanged(this, 'brand')">
|
||
<option value="">— select a brand —</option>
|
||
{% for b in brands|default([]) %}
|
||
<option value="{{ b }}">{{ b }}</option>
|
||
{% endfor %}
|
||
<option value="__new__">➕ New brand…</option>
|
||
</select>
|
||
<input type="text" id="brand" name="brand" value="{{ form_brand|default('') }}"
|
||
placeholder="Type new brand name" required
|
||
style="display:none;margin-top:0.4rem;">
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="count">Quantity</label>
|
||
<input type="number" id="count" name="count" value="{{ form_count|default(1) }}" min="1" max="50">
|
||
<small class="text-muted">Labels are auto-generated (e.g. Eneloop 001, Eneloop 002)</small>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="notes">Notes</label>
|
||
<textarea id="notes" name="notes" placeholder="Optional notes applied to all batteries…">{{ form_notes|default('') }}</textarea>
|
||
</div>
|
||
|
||
<div class="form-actions">
|
||
<button class="btn btn-primary" type="submit">Add Batteries</button>
|
||
<a class="btn btn-secondary" href="{{ url_for('dashboard') }}">Cancel</a>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
|
||
<script>
|
||
function brandSelectChanged(sel, inputId) {
|
||
var input = document.getElementById(inputId);
|
||
if (sel.value === '__new__' || sel.value === '') {
|
||
input.style.display = '';
|
||
input.value = '';
|
||
input.focus();
|
||
} else {
|
||
input.style.display = 'none';
|
||
input.value = sel.value;
|
||
}
|
||
}
|
||
|
||
// Restore state on error re-render (form_brand set)
|
||
(function () {
|
||
var input = document.getElementById('brand');
|
||
var sel = document.getElementById('brand-select');
|
||
if (!input.value) return;
|
||
for (var i = 0; i < sel.options.length; i++) {
|
||
if (sel.options[i].value === input.value) {
|
||
sel.value = input.value;
|
||
input.style.display = 'none';
|
||
return;
|
||
}
|
||
}
|
||
sel.value = '__new__';
|
||
input.style.display = '';
|
||
}());
|
||
</script>
|
||
{% endblock %}
|