Class: Yattho::Forms::Dsl::FormReferenceInput

Inherits:
Input
  • Object
show all
Defined in:
lib/yattho/forms/dsl/form_reference_input.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Input

Input::DEFAULT_SIZE, Input::SIZE_MAPPINGS, Input::SIZE_OPTIONS, Input::SPACE_DELIMITED_ARIA_ATTRIBUTES

Instance Attribute Summary collapse

Attributes inherited from Input

#builder, #caption, #form, #form_control, #ids, #input_arguments, #label_arguments, #validation_message

Instance Method Summary collapse

Methods inherited from Input

#add_input_aria, #add_input_classes, #add_input_data, #add_label_classes, #autofocus!, #caption?, #caption_id, #caption_template?, #disabled?, #focusable?, #full_width?, #hidden?, #input?, #invalid?, #merge_input_arguments!, #need_validation_element?, #remove_input_data, #render_caption_template, #required?, #size, #valid?, #validation_arguments, #validation_id, #validation_message_arguments, #validation_messages

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(*fields_for_args, builder:, form:, nested: true, **fields_for_kwargs, &block) ⇒ FormReferenceInput

For situations like this where an association exists between two models, the nested attributes approach works great. However sometimes all you want is to compose two forms together that aren’t connected by an association. In such cases the fields will still include the name of the parent model, eg. ‘user[street]` instead of what we want, `address`. To render the form independent of the parent, pass `nested: false`.



32
33
34
35
36
37
38
39
# File 'lib/yattho/forms/dsl/form_reference_input.rb', line 32

def initialize(*fields_for_args, builder:, form:, nested: true, **fields_for_kwargs, &block)
  @fields_for_args = fields_for_args
  @fields_for_kwargs = fields_for_kwargs
  @nested = nested
  @ref_block = block

  super(builder: builder, form: form, **fields_for_kwargs)
end

Instance Attribute Details

#fields_for_argsObject (readonly)

Returns the value of attribute fields_for_args.



8
9
10
# File 'lib/yattho/forms/dsl/form_reference_input.rb', line 8

def fields_for_args
  @fields_for_args
end

#fields_for_kwargsObject (readonly)

Returns the value of attribute fields_for_kwargs.



8
9
10
# File 'lib/yattho/forms/dsl/form_reference_input.rb', line 8

def fields_for_kwargs
  @fields_for_kwargs
end

#nestedObject (readonly) Also known as: nested?

Returns the value of attribute nested.



8
9
10
# File 'lib/yattho/forms/dsl/form_reference_input.rb', line 8

def nested
  @nested
end

#ref_blockObject (readonly)

Returns the value of attribute ref_block.



8
9
10
# File 'lib/yattho/forms/dsl/form_reference_input.rb', line 8

def ref_block
  @ref_block
end

Instance Method Details

#labelObject



49
50
51
# File 'lib/yattho/forms/dsl/form_reference_input.rb', line 49

def label
  nil
end

#nameObject



45
46
47
# File 'lib/yattho/forms/dsl/form_reference_input.rb', line 45

def name
  nil
end

#to_componentObject



41
42
43
# File 'lib/yattho/forms/dsl/form_reference_input.rb', line 41

def to_component
  FormReference.new(input: self)
end

#typeObject



53
54
55
# File 'lib/yattho/forms/dsl/form_reference_input.rb', line 53

def type
  :form
end