From 208041c3d856cd1314546c79805860c1378f2410 Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Sat, 10 Mar 2018 16:13:55 +0100 Subject: [PATCH] Fix cleaning custom profile - picked from bagage/brouter-web@8bcb267 - set default value to what is used in code, display text might change - keep currently selected profile on clean when other than custom --- js/control/RoutingOptions.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/js/control/RoutingOptions.js b/js/control/RoutingOptions.js index bc70a2b..6786660 100644 --- a/js/control/RoutingOptions.js +++ b/js/control/RoutingOptions.js @@ -1,5 +1,5 @@ BR.RoutingOptions = BR.Control.extend({ - + onAdd: function (map) { $('#profile-alternative').on('changed.bs.select', this._getChangeHandler()); @@ -12,6 +12,8 @@ BR.RoutingOptions = BR.Control.extend({ option.text = profiles[i]; profiles_list.appendChild(option); } + // set default value, used as indicator for empty custom profile + profiles_list.children[0].value = "Custom"; // profile is empty at start, select next one profiles_list.children[1].selected = true; return BR.Control.prototype.onAdd.call(this, map); @@ -67,13 +69,18 @@ BR.RoutingOptions = BR.Control.extend({ option; profiles_grp = L.DomUtil.get('profile'); - option = profiles_grp.children[0] - option.value = profile; + option = profiles_grp.children[0]; + option.value = profile || "Custom"; option.disabled = !profile; - $('#profile').find('option:selected').each(function(index) { - $(this).prop('selected', false); - }); + if (profile) { + $('#profile').find('option:selected').each(function(index) { + $(this).prop('selected', false); + }); + } else if (option.selected) { + // clear, select next in group when custom deselected + profiles_grp.children[1].selected = true; + } option.selected = !!profile; @@ -87,7 +94,7 @@ BR.RoutingOptions = BR.Control.extend({ option = profiles_grp.children[0], profile = null; - if (!option.disabled) { + if (option.value !== "Custom") { profile = option.value; } return profile;