diff --git a/games/static/js/qol.js b/games/static/js/qol.js new file mode 100644 index 0000000..cda1368 --- /dev/null +++ b/games/static/js/qol.js @@ -0,0 +1,29 @@ +/** + * @description Sync select field with input field until user focuses it. + * @param {HTMLSelectElement} sourceElementSelector + * @param {HTMLInputElement} targetElementSelector + */ +function syncSelectInputUntilChanged( + sourceElementSelector, + targetElementSelector +) { + const sourceElement = document.querySelector(sourceElementSelector); + const targetElement = document.querySelector(targetElementSelector); + function sourceElementHandler(event) { + let selected = event.target.value; + let selectedValue = document.querySelector( + `#id_game option[value='${selected}']` + ).textContent; + targetElement.value = selectedValue; + } + function targetElementHandler(event) { + sourceElement.removeEventListener("change", sourceElementHandler); + } + + sourceElement.addEventListener("change", sourceElementHandler); + targetElement.addEventListener("focus", targetElementHandler); +} + +window.addEventListener("load", () => { + syncSelectInputUntilChanged("#id_game", "#id_name"); +}); diff --git a/games/templates/add_edition.html b/games/templates/add_edition.html new file mode 100644 index 0000000..73784a4 --- /dev/null +++ b/games/templates/add_edition.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} + +{% block title %}{{ title }}{% endblock title %} + +{% block content %} +
+{% endblock content %} + +{% block scripts %} +{% load static %} + +{% endblock scripts %} \ No newline at end of file diff --git a/games/templates/base.html b/games/templates/base.html index 1161774..46d3787 100644 --- a/games/templates/base.html +++ b/games/templates/base.html @@ -12,7 +12,7 @@ - +