pedagogy: auto fill search form from get arguments in URL

This commit is contained in:
Antoine Bartuccio 2019-07-05 16:18:16 +02:00
parent 6f8ec4740c
commit 3063e4a24f
Signed by: klmp200
GPG Key ID: E7245548C53F904B

View File

@ -48,6 +48,22 @@
{% endfor %} {% endfor %}
<script> <script>
// Auto fill from get arguments
var urlParams = new URLSearchParams(window.location.search);
function autofillCheckboxRadio(name){
if (urlParams.has(name)){ $("input[name='" + name + "']").each(function(){
if ($(this).attr("value") == urlParams.get(name))
$(this).prop("checked", true);
});
}
}
if (urlParams.has("search"))
$("input[name='search']").first().prop("value", urlParams.get("search"));
autofillCheckboxRadio("department");
autofillCheckboxRadio("credit_type");
autofillCheckboxRadio("semester");
// Allow unchecking a radio button when we click on it // Allow unchecking a radio button when we click on it
// Keep a state of what is checked // Keep a state of what is checked
var formStates = {}; var formStates = {};