<% if is_polymorphic? %>
<%= field_wrapper **field_wrapper_args, help: @field.polymorphic_help || '' do %> <%= @form.select @field.type_input_foreign_key, @field.types.map { |type| [Avo.resource_manager.get_resource_by_model_class(type.to_s).name, type.to_s] }, { value: @field.value, include_blank: @field.placeholder, }, { class: classes("w-full"), data: { **@field.get_html(:data, view: view, element: :input), action: "change->belongs-to-field#changeType #{field_html_action}", 'belongs-to-field-target': "select", }, disabled: disabled } %> <% # If the select field is disabled, no value will be sent. It's how HTML works. # Thus the extra hidden field to actually send the related id to the server. if disabled %> <%= @form.hidden_field @field.type_input_foreign_key %> <% end %> <% end %> <% @field.types.each do |type| %> <% end %>
<% else %> <%= field_wrapper **field_wrapper_args.merge!(data: reload_data) do %> <% if @field.is_searchable? %> <%= render Avo::Pro::SearchableAssociations::AutocompleteComponent.new form: @form, field: @field, model_key: @field.target_resource&.model_key, foreign_key: @field.id_input_foreign_key, resource: @resource, disabled: disabled, classes: classes("w-full"), view: view, style: @field.get_html(:style, view: view, element: :input) %> <% else %> <%= @form.select @field.id_input_foreign_key, @field.options, { include_blank: @field.placeholder, value: @field.value }, { class: classes("w-full"), data: @field.get_html(:data, view: view, element: :input), disabled: disabled, style: @field.get_html(:style, view: view, element: :input) } %> <% # If the select field is disabled, no value will be sent. It's how HTML works. # Thus the extra hidden field to actually send the related id to the server. if disabled %> <%= @form.hidden_field @field.id_input_foreign_key %> <% end %> <% end %> <% if field.can_create? %> <% if !disabled && create_path.present? %> <%= link_to t("avo.create_new_item", item: @field.name.downcase), create_path, class: "text-sm", data: { turbo_prefetch: false } %> <% end %> <% end %> <% end %> <% end %>