From 55ff3cd1a979148e58ed57e241cc7e0de1508833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 9 Nov 2023 15:20:30 +0100 Subject: [PATCH] Pre-fill year when adding edition --- CHANGELOG.md | 2 +- games/forms.py | 1 + games/static/js/add_edition.js | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93e377e..745a091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,7 @@ * added a new sort_name field that gets automatically created * automatically fill certain values in forms: * new game: name and sort name after typing - * new edition: name and sort name when selecting game + * new edition: name, sort name, and year when selecting game * new purchase: platform when selecting edition ## 1.3.0 / 2023-11-05 15:09+01:00 diff --git a/games/forms.py b/games/forms.py index f1e17e8..8955284 100644 --- a/games/forms.py +++ b/games/forms.py @@ -80,6 +80,7 @@ class IncludeNameSelect(forms.Select): option = super().create_option(name, value, *args, **kwargs) if value: option["attrs"]["data-name"] = value.instance.name + option["attrs"]["data-year"] = value.instance.year_released return option diff --git a/games/static/js/add_edition.js b/games/static/js/add_edition.js index 4ed0035..dabfca6 100644 --- a/games/static/js/add_edition.js +++ b/games/static/js/add_edition.js @@ -13,6 +13,12 @@ let syncData = [ "target": "#id_sort_name", "target_value": "value" }, + { + "source": "#id_game", + "source_value": "dataset.year", + "target": "#id_year_released", + "target_value": "value" + }, ] syncSelectInputUntilChanged(syncData, "form");