Even after customizing the Field::BelongsTo form to include_blank: false it still doesn't work. Checked on the code, and saw that it automatically adds a blank option thru
[nil] + candidate_resources
If I customize the FIeld::BelongsTo::Form views to
<%= f.select(field.permitted_attribute,
options_for_select(field.associated_resource_options, field.selected_option),
include_blank: true) %>
then it would have two blank options.
Removing the default blank option from BelongsTo#associated_resource_options would force anyone who wants to add a blank option to customize the view. This sounds inconvenient.
Ideally BelongsTo#associated_resource_options would add a blank option if the association was configured as belongs_to :resource, optional: true in the model.
The downside however is that we can't do
<%= f.select(field.permitted_attribute,
options_for_select(field.associated_resource_options, field.selected_option),
include_blank: "None") %>
since there will be the two blank values.
Open to tips on how to go about this (ideally for a single model), as I can't find a lot about it elsewhere.
@G-Rath - Sorry, I don't quite get what you mean. Can you elaborate? Which situation would produce two blank values?
Are you referring to detecting it like @cabe56 describes (based on the original association's optional option), in addition to Administrate providing a include_blank option for the field? Or is it something else?
Most helpful comment
Removing the default blank option from
BelongsTo#associated_resource_optionswould force anyone who wants to add a blank option to customize the view. This sounds inconvenient.Ideally
BelongsTo#associated_resource_optionswould add a blank option if the association was configured asbelongs_to :resource, optional: truein the model.