Class: Admin::AssociationFieldComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
lib/generators/infold/templates/install/app/components/admin/association_field_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(association_name, search_path, form, id_field, name_field, nested_form: false) ⇒ AssociationFieldComponent

Returns a new instance of AssociationFieldComponent.



5
6
7
8
9
10
11
12
13
# File 'lib/generators/infold/templates/install/app/components/admin/association_field_component.rb', line 5

def initialize(association_name, search_path, form, id_field, name_field, nested_form:false)
  @association_name = association_name
  @search_path = search_path
  @form = form
  @id_field = id_field
  @name_field = name_field
  @nested_form = nested_form
  @turbo_frame_id = "relation_#{ SecureRandom.hex(3) }#{ @nested_form ? '_NEW_RECORD' : '' }"
end

Instance Method Details

#name_field_tagObject



15
16
17
18
19
20
21
22
23
# File 'lib/generators/infold/templates/install/app/components/admin/association_field_component.rb', line 15

def name_field_tag
  classes = %W(form-control)
  classes << 'is-invalid' if helpers.admin_field_invalid?(@form, @id_field) || helpers.admin_field_invalid?(@form, @association_name)
  text_field_tag '',
                 @form.object.send(@name_field),
                 disabled: true,
                 class: classes.join(' '),
                 data: { relation_search_target: 'selectedName' }
end