Enforce parent device hierarchy: slots/size unset, battery summary, sub-component toggle

This commit is contained in:
2026-06-08 12:57:31 -05:00
parent 75fe4fe575
commit 2a54cd8297
5 changed files with 135 additions and 33 deletions
+37 -2
View File
@@ -18,6 +18,16 @@
placeholder="e.g. Game Controller" required>
</div>
{% if not prefill_parent %}
<div class="form-group">
<label style="display:flex;align-items:center;gap:0.5rem;font-weight:normal;cursor:pointer;">
<input type="checkbox" id="has-subcomponents" onchange="toggleSubcomponents(this)">
This device has sub-components (batteries tracked per sub-component, not directly)
</label>
</div>
{% endif %}
<div id="battery-fields">
<div class="form-group">
<label for="battery_slots">Battery Slots <span class="text-danger">*</span></label>
<input type="number" id="battery_slots" name="battery_slots"
@@ -44,6 +54,7 @@
placeholder="e.g. CR123A"
style="display:{% if _cur_size and _cur_size not in _preset_sizes %}''{% else %}none{% endif %};margin-top:0.4rem;">
</div>
</div><!-- #battery-fields -->
<div class="form-group">
<label>Type</label>
@@ -68,14 +79,18 @@
<div class="form-group">
<label>Location</label>
{% set _cur_loc = form_location|default('') %}
<select id="location-select" onchange="metaSelectChanged(this,'location')">
<option value="">— none —</option>
{% for loc in device_locations|default([]) %}
<option value="{{ loc }}">{{ loc }}</option>
<option value="{{ loc }}" {% if _cur_loc == loc %}selected{% endif %}>{{ loc }}</option>
{% endfor %}
{% if _cur_loc and _cur_loc not in device_locations|default([]) %}
<option value="{{ _cur_loc }}" selected>{{ _cur_loc }}</option>
{% endif %}
<option value="__new__"> New location…</option>
</select>
<input type="text" id="location" name="location" value=""
<input type="text" id="location" name="location" value="{{ _cur_loc }}"
placeholder="e.g. Living Room, Bedroom"
style="display:none;margin-top:0.4rem;">
</div>
@@ -93,6 +108,26 @@
</div>
<script>
function toggleSubcomponents(cb) {
var fields = document.getElementById('battery-fields');
var slots = document.getElementById('battery_slots');
var size = document.getElementById('battery_size');
if (cb.checked) {
fields.style.display = 'none';
slots.value = '0';
slots.removeAttribute('required');
slots.removeAttribute('min');
size.value = '';
size.removeAttribute('required');
} else {
fields.style.display = '';
slots.value = '1';
slots.setAttribute('required', '');
slots.setAttribute('min', '1');
size.setAttribute('required', '');
}
}
function metaSelectChanged(sel, inputId) {
var input = document.getElementById(inputId);
if (sel.value === '__new__') {