Class: FlexiAdmin::Components::Resource::AutocompleteComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
Helpers::ResourceHelper
Defined in:
lib/flexi_admin/components/resource/autocomplete_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ResourceHelper

#autocomplete_path, #bulk_action_path, #datalist_path, #edit_resource_path, #paginate, #resource__path, #resource_input_name, #resource_path, #resources_path, #scope, #scope_plural, #scope_singular

Constructor Details

#initialize(resource = nil, scope:, fields: [:title], action: :select, parent: nil, path: nil, value: nil, **html_options) ⇒ AutocompleteComponent

Returns a new instance of AutocompleteComponent.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 11

def initialize(resource = nil, scope:, fields: [:title],
              action: :select, parent: nil, path: nil,
              value: nil, **html_options)
  @resource = resource
  @scope = scope
  @parent = parent
  @fields = fields
  @path = path
  @action = action
  @value = value

  @html_options = html_options
  @width = html_options.delete(:width)
  @required = html_options[:required]
  @style = html_options.delete(:style)
  @disabled = html_options.key?(:disabled) ? html_options[:disabled] : false
  @name = html_options[:name] || resource_input_name

  validate_action!
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def action
  @action
end

#disabledObject (readonly)

Returns the value of attribute disabled.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def disabled
  @disabled
end

#fieldsObject (readonly)

Returns the value of attribute fields.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def fields
  @fields
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def html_options
  @html_options
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def path
  @path
end

#requiredObject (readonly)

Returns the value of attribute required.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def required
  @required
end

#resourceObject (readonly)

Returns the value of attribute resource.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def resource
  @resource
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def value
  @value
end

#widthObject (readonly)

Returns the value of attribute width.



8
9
10
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 8

def width
  @width
end

Instance Method Details

#autocomplete_optionsObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/flexi_admin/components/resource/autocomplete_component.rb', line 32

def autocomplete_options
  {
    style: 'border-top-right-radius: 0.4rem; border-bottom-right-radius: 0.4rem;',
    data: { autocomplete_target: 'input',
            action: 'keyup->autocomplete#keyup focusout->autocomplete#onFocusOut',
            autocomplete_search_path: get_path,
            autocomplete_is_disabled: disabled,
            field_type: kind }.merge(html_options)
  }
end