Class: Fluxbit::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Fluxbit::FormBuilder
- Includes:
- ActionView::Helpers::OutputSafetyHelper
- Defined in:
- app/helpers/fluxbit/form_builder.rb
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #error_for(method) ⇒ Object
- #errors_summary(within: :container) ⇒ Object
- #fluxbit_inline_error_for(method, **options, &block) ⇒ Object
-
#fx_select(method, **options, &block) ⇒ Object
select(object, method, choices = nil, options = {}, html_options = {}, &block) public.
Instance Attribute Details
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'app/helpers/fluxbit/form_builder.rb', line 5 def template @template end |
Instance Method Details
#error_for(method) ⇒ Object
36 37 38 39 40 41 |
# File 'app/helpers/fluxbit/form_builder.rb', line 36 def error_for(method) return if object.blank? return unless object.errors.key?(method) raw object.errors.(method)&.first end |
#errors_summary(within: :container) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/fluxbit/form_builder.rb', line 9 def errors_summary(within: :container) return if object.blank? return unless object.errors.any? title = I18n.t( "polaris.form_builder.errors_summary", count: object.errors.count, model: object.class.model_name.human.downcase ) render Fluxbit::BannerComponent.new( title: title, status: :critical, within: within, data: { errors_summary: true } ) do || [ render(Fluxbit::ListComponent.new) do |list| object.errors..each do |error| list.with_item { error.html_safe } end end, (template.capture { yield() } if block_given?) ].compact.join.html_safe end end |
#fluxbit_inline_error_for(method, **options, &block) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'app/helpers/fluxbit/form_builder.rb', line 43 def fluxbit_inline_error_for(method, **, &block) = error_for(method) return unless render(Fluxbit::InlineErrorComponent.new(**, &block)) do end end |
#fx_select(method, **options, &block) ⇒ Object
select(object, method, choices = nil, options = {}, html_options = {}, &block) public
78 79 80 81 82 83 84 85 |
# File 'app/helpers/fluxbit/form_builder.rb', line 78 def fx_select(method, **, &block) [:error] ||= error_for(method) [:error] = !![:error] if [:error_hidden] && [:error] value = object&.public_send(method) [:selected] = value if value.present? render Fluxbit::Form::SelectComponent.new(form: self, attribute: method, **, &block) end |