diff --git a/app/helpers/extended_fields_helper.rb b/app/helpers/extended_fields_helper.rb
index 33037e23b..0439ec09b 100644
--- a/app/helpers/extended_fields_helper.rb
+++ b/app/helpers/extended_fields_helper.rb
@@ -349,8 +349,14 @@ def extended_field_choice_select_editor(name, value, options, extended_field, ch
:complete => "Element.hide('#{id_for_extended_field(extended_field)}_#{level}_spinner')")
}
- select_tag("#{name}[#{level}]", option_tags, default_options.merge(options)) +
- ""
+ html = select_tag("#{name}[#{level}][preset]", option_tags, default_options.merge(options))
+ html += ""
+ if extended_field.user_choice_addition?
+ user_supplied_id = "#{id_for_extended_field(extended_field)}_custom"
+ html += ' OR add your own '
+ html += text_field_tag("#{name}[#{level}][custom]", nil, :size => 10, :id => user_supplied_id)
+ end
+ html
end
def extended_field_choice_autocomplete_editor(name, value, options, extended_field, choices, level = 1)
diff --git a/lib/extended_content_helpers.rb b/lib/extended_content_helpers.rb
index 6c1f1dd1e..5e888a3b2 100644
--- a/lib/extended_content_helpers.rb
+++ b/lib/extended_content_helpers.rb
@@ -85,6 +85,18 @@ def extended_content_field_xml_tag(options = {})
xsi_type = options[:xsi_type] || nil
extended_field = options[:extended_field] || nil
+ # With choices from a dropdown, we can have preset dropdown and custom text field
+ # So before we go any further, make sure we convert the values from Hash to either
+ # the preset or custom value depending on which one is filled in
+ if extended_field.ftype == 'choice'
+ value.each do |key,choice_value|
+ next unless choice_value.is_a?(Hash)
+ choice = choice_value['preset'] # Preset values come from the dropdown
+ choice = choice_value['custom'] unless choice_value['custom'].blank? # Custom values come from a text field
+ value[key] = choice
+ end
+ end
+
options = {}
options.merge!(:xml_element_name => xml_element_name) unless xml_element_name.blank?
options.merge!(:xsi_type => xsi_type) unless xsi_type.blank?
@@ -112,7 +124,7 @@ def extended_content_field_xml_tag(options = {})
matching_choice = Choice.matching(l,v)
# Handle the creation of new choices where the choice is not recognised.
- if !matching_choice && extended_field.ftype == 'autocomplete' && extended_field.user_choice_addition?
+ if !matching_choice && %w(autocomplete choice).include?(extended_field.ftype) && extended_field.user_choice_addition?
index = value.to_a.index([k, v])
to_check = v