Class: RubyUIAdmin::Views::ActionForm

Inherits:
Phlex::HTML
  • Object
show all
Includes:
UI, PathHelpers, RailsHelpers
Defined in:
app/components/ruby_ui_admin/views/action_form.rb

Overview

The inner form of a custom action (message + fields + buttons). Shared by the action page (Views::Action) and the inline action dialog (Views::ActionTrigger).

Instance Method Summary collapse

Methods included from PathHelpers

#attachment_url, #resource_edit_path, #resource_index_path, #resource_new_path, #resource_show_path

Constructor Details

#initialize(resource:, action:, action_id:, record_ids: [], frame_id: nil) ⇒ ActionForm

Returns a new instance of ActionForm.



12
13
14
15
16
17
18
# File 'app/components/ruby_ui_admin/views/action_form.rb', line 12

def initialize(resource:, action:, action_id:, record_ids: [], frame_id: nil)
  @resource = resource
  @action = action
  @action_id = action_id
  @record_ids = record_ids
  @frame_id = frame_id
end

Instance Method Details

#render_formObject



32
33
34
35
36
37
38
39
40
# File 'app/components/ruby_ui_admin/views/action_form.rb', line 32

def render_form
  form(action: action_path, method: "post", enctype: form_enctype, class: "space-y-5", data: {turbo_frame: "_top"}) do
    input(type: "hidden", name: "authenticity_token", value: form_authenticity_token)
    record_id_fields
    render_message
    @action.get_fields.each { |field| render_field(field) }
    render_actions
  end
end

#view_templateObject

When loaded into the modal's <turbo-frame>, wrap the form in the matching frame so Turbo swaps it in. data-turbo-frame="_top" makes the submit break out into a full visit (POST→303→redirect+flash) instead of just reloading the frame. On the standalone action page (no frame_id) the form renders bare and _top is a harmless no-op.



24
25
26
27
28
29
30
# File 'app/components/ruby_ui_admin/views/action_form.rb', line 24

def view_template
  if @frame_id
    tag(:turbo_frame, id: @frame_id) { render_form }
  else
    render_form
  end
end