From edcab26821011c7be47a4b2d504423b2407a5b2c Mon Sep 17 00:00:00 2001 From: Suhail vs Date: Sat, 14 Jul 2018 22:21:23 +0530 Subject: [PATCH] fixed issue #1: don't make ajax request when no country is selected. also disable the city select while ajax request --- hr/templates/hr/person_form.html | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/hr/templates/hr/person_form.html b/hr/templates/hr/person_form.html index dabced4..dd1bac6 100644 --- a/hr/templates/hr/person_form.html +++ b/hr/templates/hr/person_form.html @@ -18,16 +18,23 @@

Person Form

$("#id_country").change(function () { var url = $("#personForm").attr("data-cities-url"); var countryId = $(this).val(); + if (countryId == 0) { //Not selected + $("#id_city").html(""); + } else { + // disable the city select while the ajax request + $("#id_city").prop('disabled',true); - $.ajax({ - url: url, - data: { - 'country': countryId - }, - success: function (data) { - $("#id_city").html(data); - } - }); + $.ajax({ + url: url, + data: { + 'country': countryId + }, + success: function (data) { + $("#id_city").removeAttr("disabled"); + $("#id_city").html(data); + } + }); + } });