diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-07-16 11:09:48 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-07-16 14:58:13 +0100 |
commit | 859fe1336c653bc3a533fd7f1be23cc56b61c03c (patch) | |
tree | 8e10c7e5d641e83913ec4563c23f9df49ff4b607 | |
parent | 90afa8d790808979d1b1fd9c327e0139013b3b90 (diff) |
Make correct selection from single filter choice.
If a single filter item, that was in multiple groups, was selected,
then the entry in the last group was being selected in the category
dropdown when starting a new report. Make sure we check for a match
in the group first, the same behaviour as when there is an existing
category.
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index d79f17049..ca36d5b46 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -1310,6 +1310,20 @@ fixmystreet.update_pin = function(lonlat, savePushState) { } }; +(function() { // fetch_reporting_data closure + +function re_select(group, category) { + var cat_in_group = $("#form_category optgroup[label=\"" + group + "\"] option[value=\"" + category + "\"]"); + if (cat_in_group.length) { + cat_in_group.prop({selected:true}); + return true; + } else if ($("#form_category option[value=\"" + category + "\"]").length) { + $("#form_category").val(category); + return true; + } + return false; +} + fixmystreet.fetch_reporting_data = function() { $.getJSON('/report/new/ajax', { latitude: $('#fixmystreet\\.latitude').val(), @@ -1364,16 +1378,12 @@ fixmystreet.fetch_reporting_data = function() { } $('#form_category_row').html(data.category); - var cat_in_group = $("#form_category optgroup[label=\"" + old_category_group + "\"] option[value=\"" + old_category + "\"]"); - if (cat_in_group.length) { - cat_in_group.prop({selected:true}); - } else if ($("#form_category option[value=\"" + old_category + "\"]").length) { - $("#form_category").val(old_category); - } else if (filter_category !== undefined && $("#form_category option[value='" + filter_category + "']").length) { + var reselected = re_select(old_category_group, old_category); + if (!reselected && filter_category !== undefined) { // If the category filter appears on the map and the user has selected // something from it, then pre-fill the category field in the report, // if it's a value already present in the drop-down. - $("#form_category").val(filter_category); + re_select(old_category_group, filter_category); } fixmystreet.set_up.category_groups(old_category_group); @@ -1408,6 +1418,8 @@ fixmystreet.fetch_reporting_data = function() { }); }; +})(); // fetch_reporting_data closure + fixmystreet.display = { begin_report: function(lonlat, saveHistoryState) { lonlat = fixmystreet.maps.begin_report(lonlat); |