<% if @field.is_searchable? %>
<%= field_wrapper stacked: true,
field: @field,
view: Avo::ViewInquirer.new("edit"),
form:,
index: 0,
resource: @resource,
label_for: @field.id,
label: @field.name.singularize.downcase do %>
<%= render Avo::Pro::SearchableAssociations::AutocompleteComponent.new form: form,
classes: input_classes("w-full"),
field: @field,
model_key: @field.target_resource&.model_key,
foreign_key: 'related_id',
resource: @resource,
view: Avo::ViewInquirer.new(:new)
%>
<% end %>
<% else %>
<%= avo_edit_field :related_id,
as: :select,
form: form,
name: @field.name.singularize,
options: options_for_select(@options, selected: nil, disabled: t("avo.more_records_available")),
include_blank: t('avo.choose_an_option'),
stacked: true,
classes: 'w-full'
%>
<% end %>
<%#
It is important to render this hidden field to allow selective rendering of the turbo frame.
(e.g. in the case of "Attach and Attach Another")
Without this, the entire page will be reloaded when the form is submitted.
%>
<%= hidden_field_tag :turbo_frame, params[:turbo_frame] %>
<% @attach_fields&.each_with_index do |field, index| %>
<%= render(Avo::Items::SwitcherComponent.new(
resource: @related_resource,
item: field,
index: index + 1,
view: @view,
form: form,
field_component_extra_args: {
stacked: true,
classes: 'w-full'}
)) %>
<% end %>