diff --git a/lib/carmen/rails/action_view/form_helper.rb b/lib/carmen/rails/action_view/form_helper.rb
index ba9daf8..d5f5510 100644
--- a/lib/carmen/rails/action_view/form_helper.rb
+++ b/lib/carmen/rails/action_view/form_helper.rb
@@ -94,6 +94,11 @@ def region_options_for_select(regions, selected=nil, options={})
unless priority_regions.empty?
region_options += options_for_select(priority_regions, selected)
region_options += ""
+
+ # If a priority region is selected, don't select it again in the main list.
+ # This prevents some browsers from selecting the second occurance of this region,
+ # which makes it difficult to select an alternative priority region.
+ selected = nil if priority_region_codes.include?(selected)
end
end
diff --git a/test/carmen/action_view/helpers/form_helper_test.rb b/test/carmen/action_view/helpers/form_helper_test.rb
index 1794b44..5b5fd29 100644
--- a/test/carmen/action_view/helpers/form_helper_test.rb
+++ b/test/carmen/action_view/helpers/form_helper_test.rb
@@ -101,6 +101,23 @@ def test_priority_country_select_deprecated_api
assert_equal_markup(expected, html)
end
+ def test_country_select_selected_priority_region_not_selected_twice
+ @object.country_code = 'ES'
+
+ html = country_select(@object, :country_code, :priority => ['ES'])
+ expected = <<-HTML
+
+ HTML
+
+ assert_equal_markup(expected, html)
+ end
+
def test_basic_subregion_select
oceania = Carmen::Country.coded('OC')
expected = <<-HTML
diff --git a/test/test_helper.rb b/test/test_helper.rb
index f4918b2..bd63c69 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -30,6 +30,12 @@ def assert_equal_markup(expected, actual, message=nil)
private
def clean_markup(markup)
+ clean_whitespace(markup).gsub(/( [a-zA-Z_]*="[^"]*")+/) do |match|
+ ' ' + match.strip!.split(' ').sort.join(' ')
+ end
+ end
+
+ def clean_whitespace(markup)
markup.
gsub(/\s+/, ' '). # cleanup whitespace
gsub(/>\s/, '>'). # kill space after tags