fix: always add an empty option in mandatory
This commit is contained in:
parent
253ddc56e2
commit
9e0aadd2dd
2 changed files with 7 additions and 9 deletions
|
@ -19,7 +19,13 @@
|
|||
%label.fr-label{ for: "#{@champ.id}_radio_option_other" }
|
||||
Autre
|
||||
- else
|
||||
= @form.select :value, @champ.options_without_empty_value_when_mandatory(@champ.options), { selected: @champ.selected }, required: @champ.required?, id: @champ.input_id, class: select_class_names, aria: { describedby: @champ.describedby_id }
|
||||
= @form.select :value,
|
||||
@champ.options.compact_blank,
|
||||
{ selected: @champ.selected, include_blank: true },
|
||||
required: @champ.required?,
|
||||
id: @champ.input_id,
|
||||
class: select_class_names,
|
||||
aria: { describedby: @champ.describedby_id }
|
||||
|
||||
- if @champ.drop_down_other?
|
||||
= render EditableChamp::DropDownOtherInputComponent.new(form: @form, champ: @champ)
|
||||
|
|
|
@ -477,14 +477,6 @@ class TypeDeChamp < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
# historicaly we added a blank ("") option by default to avoid wrong selection
|
||||
# see self.parse_drop_down_list_value
|
||||
# then rails decided to add this blank ("") option when the select is required
|
||||
# so we revert this change
|
||||
def options_without_empty_value_when_mandatory(options)
|
||||
mandatory? ? options.compact_blank : options
|
||||
end
|
||||
|
||||
def drop_down_list_options?
|
||||
drop_down_list_options.any?
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue