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
|
||||
|
||||
Reference in New Issue
Block a user