Class: Avo::Fields::BelongsToField::AutocompleteComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Avo::Fields::BelongsToField::AutocompleteComponent
- Defined in:
- app/components/avo/fields/belongs_to_field/autocomplete_component.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #field_label ⇒ Object
- #field_value ⇒ Object
-
#initialize(form:, field:, model_key:, foreign_key:, disabled: false, type: nil, resource: nil, polymorphic_record: nil, view: nil, style: nil, classes: nil) ⇒ AutocompleteComponent
constructor
A new instance of AutocompleteComponent.
- #reflection_class ⇒ Object
Constructor Details
#initialize(form:, field:, model_key:, foreign_key:, disabled: false, type: nil, resource: nil, polymorphic_record: nil, view: nil, style: nil, classes: nil) ⇒ AutocompleteComponent
Returns a new instance of AutocompleteComponent.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/components/avo/fields/belongs_to_field/autocomplete_component.rb', line 7 def initialize(form:, field:, model_key:, foreign_key:, disabled: false, type: nil, resource: nil, polymorphic_record: nil, view: nil, style: nil, classes: nil) @form = form @field = field @type = type @view = view @model_key = model_key @foreign_key = foreign_key @resource = resource @disabled = disabled @style = style @classes = classes @polymorphic_record = polymorphic_record end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
4 5 6 |
# File 'app/components/avo/fields/belongs_to_field/autocomplete_component.rb', line 4 def classes @classes end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
5 6 7 |
# File 'app/components/avo/fields/belongs_to_field/autocomplete_component.rb', line 5 def view @view end |
Instance Method Details
#field_label ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'app/components/avo/fields/belongs_to_field/autocomplete_component.rb', line 21 def field_label result = @field.field_label # New records won't have the value (instantiated model) present but the polymorphic_type and polymorphic_id prefilled if should_prefill? result = @field.value&.class == @type ? @field.field_label : nil end result end |
#field_value ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'app/components/avo/fields/belongs_to_field/autocomplete_component.rb', line 32 def field_value result = @field.field_value # New records won't have the value (instantiated model) present but the polymorphic_type and polymorphic_id prefilled if should_prefill? result = @field.value&.class == @type ? @field.field_value : nil end result end |
#reflection_class ⇒ Object
43 44 45 |
# File 'app/components/avo/fields/belongs_to_field/autocomplete_component.rb', line 43 def reflection_class has_polymorphic_association? ? polymorphic_class : @resource.model_class._reflections[@field.id.to_s].klass end |