Add brand autocomplete dropdown to battery add and device install forms
Uses HTML datalist populated from distinct brands in the battery table. Removed autocomplete="off" which suppresses datalist in Chrome/Chromium.
This commit is contained in:
@@ -46,8 +46,10 @@ def create_app(config_object="config"):
|
||||
|
||||
if not brand:
|
||||
flash("Brand is required.", "error")
|
||||
brands = [r[0] for r in db.query(Battery.brand).distinct().order_by(Battery.brand).all()]
|
||||
return render_template("battery_add.html",
|
||||
form_brand="", form_count=1, form_notes=notes or ""), 400
|
||||
form_brand="", form_count=1, form_notes=notes or "",
|
||||
brands=brands), 400
|
||||
|
||||
existing = db.query(func.count(Battery.id)).filter_by(brand=brand).scalar()
|
||||
for i in range(count):
|
||||
@@ -57,7 +59,8 @@ def create_app(config_object="config"):
|
||||
flash(f"Added {count} {brand} batter{'y' if count == 1 else 'ies'}.", "success")
|
||||
return redirect(url_for("dashboard"))
|
||||
|
||||
return render_template("battery_add.html", form_count=1)
|
||||
brands = [r[0] for r in db.query(Battery.brand).distinct().order_by(Battery.brand).all()]
|
||||
return render_template("battery_add.html", form_count=1, brands=brands)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Battery — detail
|
||||
@@ -290,7 +293,8 @@ def create_app(config_object="config"):
|
||||
device = db.get(Device, device_id)
|
||||
if device is None:
|
||||
abort(404)
|
||||
return render_template("device_detail.html", device=device)
|
||||
brands = [r[0] for r in db.query(Battery.brand).distinct().order_by(Battery.brand).all()]
|
||||
return render_template("device_detail.html", device=device, brands=brands)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Devices — install batteries
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
<div class="form-group">
|
||||
<label for="brand">Brand <span class="text-danger">*</span></label>
|
||||
<input type="text" id="brand" name="brand" value="{{ form_brand|default('') }}"
|
||||
placeholder="e.g. Panasonic Eneloop" required>
|
||||
placeholder="e.g. Panasonic Eneloop" list="brand-list" required>
|
||||
<datalist id="brand-list">
|
||||
{% for b in brands|default([]) %}<option value="{{ b }}">{% endfor %}
|
||||
</datalist>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
@@ -29,12 +29,16 @@
|
||||
<h2>Install Batteries</h2>
|
||||
{% set free_slots = device.battery_slots - device.installed_count() %}
|
||||
<p class="text-muted" style="margin-bottom:0.75rem;">{{ free_slots }} slot(s) free</p>
|
||||
<datalist id="brand-list">
|
||||
{% for b in brands|default([]) %}<option value="{{ b }}">{% endfor %}
|
||||
</datalist>
|
||||
<form method="post" action="{{ url_for('device_install', device_id=device.id) }}">
|
||||
<div style="display:grid;grid-template-columns:1fr auto;gap:0.4rem;max-width:360px;align-items:center;margin-bottom:0.75rem;">
|
||||
<span style="font-weight:600;font-size:0.85rem;color:#64748b;">Brand</span>
|
||||
<span style="font-weight:600;font-size:0.85rem;color:#64748b;">Qty</span>
|
||||
{% for _ in range(4) %}
|
||||
<input type="text" name="brand[]" placeholder="e.g. Eneloop" style="padding:0.3rem 0.5rem;">
|
||||
<input type="text" name="brand[]" placeholder="e.g. Eneloop"
|
||||
list="brand-list" style="padding:0.3rem 0.5rem;">
|
||||
<input type="number" name="qty[]" value="0" min="0"
|
||||
style="padding:0.3rem 0.5rem;width:4rem;text-align:center;">
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user