Class: EasyAdmin::Fields::Form::JsonComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/easy_admin/fields/form/json_component.rb

Instance Attribute Summary

Attributes inherited from BaseComponent

#field, #form, #record, #value

Instance Method Summary collapse

Methods inherited from BaseComponent

#easy_admin_url_helpers, #helpers, #initialize, #rails_url_helpers

Methods included from EasyAdmin::FieldsHelper

#field_component, #render_field

Methods included from DashboardsHelper

#delta_badge_classes, #metric_value_classes, #render_card, #sparkline_color, #sparkline_points, #trend_direction, #trend_icon, #trend_indicator_classes

Constructor Details

This class inherits a constructor from EasyAdmin::Fields::BaseComponent

Instance Method Details

#view_templateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/components/easy_admin/fields/form/json_component.rb', line 5

def view_template
  div(class: "space-y-2") do
    label(
      for: field_id,
      class: "block text-sm font-medium text-gray-700"
    ) { field_label }
    
    div(
      class: "relative",
      data: {
        controller: "jsoneditor",
        jsoneditor_mode_value: "code",
        jsoneditor_data_value: current_json_value.to_json
      }
    ) do
      # Hidden field to store the JSON value
      input(
        type: "hidden",
        name: form_field_name,
        id: "#{field_id}_hidden",
        value: current_json_value_string,
        data: { jsoneditor_target: "hiddenField" }
      )
      
      # JSONEditor container
      div(
        id: field_id,
        data: { jsoneditor_target: "editor" },
        style: "height: 400px; border: 1px solid #d1d5db; border-radius: 0.375rem;"
      )
    end
    
    if field[:help_text].present?
      p(class: "text-sm text-gray-500") { field[:help_text] }
    end
  end
end