avo-hq/avo

Add the ability to change the view type of a field

已關閉

#2,140 建立於 2023年12月18日

 (4 則留言) (0 個反應) (0 位負責人)Ruby (308 個分叉)user submission
Back endDSL-relatedEnhancementHelp wantedTask

倉庫指標

星標
 (1,778 顆星)
PR 合併指標
 (平均合併 1天 6小時) (30 天內合併 67 個 PR)

描述

From here.

Maybe you must use a computed field on an Edit view. You can fake it like in that comment or you could pass in a computed field with the view set to :show. This will render that field as a show field in the edit view.

Example:

Image

Rough PoC:

        <% if main_panel.present? %>
          <% c.with_body do %>
            <div class="divide-y">
              <% main_panel.items.each_with_index do |field, index| %>
              <% v = field.id == :user_label ? :show : view %>
                <%= render field
                  .hydrate(resource: @resource, model: @resource.model, user: @resource.user, view: view_for(field, forced_view: v))
                  .component_for_view(view_for(field, forced_view: v))
                  .new(field: field, resource: @resource, index: index, form: form, compact: sidebar.present?)
                %>
              <% end %>
            </div>
          <% end %>
        <% end %>

貢獻者指南