Class: Effective::FormInputs::HasMany
- Inherits:
-
Effective::FormInput
- Object
- Effective::FormInput
- Effective::FormInputs::HasMany
- Defined in:
- app/models/effective/form_inputs/has_many.rb
Constant Summary collapse
- BLANK =
''.html_safe
Constants inherited from Effective::FormInput
Effective::FormInput::DEFAULT_FEEDBACK_OPTIONS, Effective::FormInput::DEFAULT_INPUT_GROUP_OPTIONS, Effective::FormInput::EMPTY_HASH, Effective::FormInput::EXCLUSIVE_CLASS_PREFIXES, Effective::FormInput::EXCLUSIVE_CLASS_SUFFIXES, Effective::FormInput::HORIZONTAL_LABEL_OPTIONS, Effective::FormInput::HORIZONTAL_WRAPPER_OPTIONS, Effective::FormInput::INLINE_LABEL_OPTIONS, Effective::FormInput::VERTICAL_WRAPPER_OPTIONS
Instance Attribute Summary
Attributes inherited from Effective::FormInput
Instance Method Summary collapse
-
#add? ⇒ Boolean
add: true.
-
#build? ⇒ Boolean
build: true.
- #can_remove_method ⇒ Object
- #collection ⇒ Object
-
#display ⇒ Object
cards: false.
-
#errors? ⇒ Boolean
errors: true.
- #input_html_options ⇒ Object
- #input_js_options ⇒ Object
-
#remove? ⇒ Boolean
remove: true.
-
#reorder? ⇒ Boolean
reorder: true.
- #to_html(&block) ⇒ Object
Methods inherited from Effective::FormInput
#feedback_options, #hint_options, #initialize, #input_group_options, #label_options, #wrapper_options
Constructor Details
This class inherits a constructor from Effective::FormInput
Instance Method Details
#add? ⇒ Boolean
add: true
45 46 47 48 49 50 51 52 |
# File 'app/models/effective/form_inputs/has_many.rb', line 45 def add? return @add unless @add.nil? @add ||= begin add = [:input].delete(:add) add.nil? ? true : add end end |
#build? ⇒ Boolean
build: true
35 36 37 38 39 40 41 42 |
# File 'app/models/effective/form_inputs/has_many.rb', line 35 def build? return @build unless @build.nil? @build ||= begin build = [:input].delete(:build) build.nil? ? true : build end end |
#can_remove_method ⇒ Object
80 81 82 83 |
# File 'app/models/effective/form_inputs/has_many.rb', line 80 def can_remove_method return @can_remove_method unless @can_remove_method.nil? @can_remove_method = ([:input].delete(:can_remove_method) || false) end |
#collection ⇒ Object
25 26 27 |
# File 'app/models/effective/form_inputs/has_many.rb', line 25 def collection Array([:input][:collection] || object.send(name)) end |
#display ⇒ Object
cards: false
30 31 32 |
# File 'app/models/effective/form_inputs/has_many.rb', line 30 def display @display ||= ([:input].delete(:cards) ? :cards : :rows) end |
#errors? ⇒ Boolean
errors: true
55 56 57 58 59 60 61 62 |
# File 'app/models/effective/form_inputs/has_many.rb', line 55 def errors? return @errors unless @errors.nil? @errors ||= begin errors = [:input].delete(:errors) errors.nil? ? true : errors end end |
#input_html_options ⇒ Object
17 18 19 |
# File 'app/models/effective/form_inputs/has_many.rb', line 17 def { class: 'form-has-many mb-4' } end |
#input_js_options ⇒ Object
21 22 23 |
# File 'app/models/effective/form_inputs/has_many.rb', line 21 def { sortable: true } end |
#remove? ⇒ Boolean
remove: true
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/effective/form_inputs/has_many.rb', line 65 def remove? return @remove unless @remove.nil? @remove ||= begin remove = [:input].delete(:remove) if remove != nil remove else opts = (object.class.[name] || {}) opts[:update_only] != true && opts[:allow_destroy] != false end end end |
#reorder? ⇒ Boolean
reorder: true
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/effective/form_inputs/has_many.rb', line 86 def reorder? return @reorder unless @reorder.nil? @reorder ||= begin reorder = [:input].delete(:reorder) if reorder != nil reorder else build_resource().class.columns_hash['position']&.type == :integer end end end |
#to_html(&block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/effective/form_inputs/has_many.rb', line 6 def to_html(&block) object.send(name).build() if build? && collection.blank? errors = (@builder.error(name) if errors?) || BLANK can_remove_method errors + content_tag(:div, [:input].except(:collection)) do has_many_fields_for(block) + has_many_links_for(block) end end |