Class: UiBibz::Ui::Core::Navigations::ToolbarForm

Inherits:
Base
  • Object
show all
Includes:
ActionView::Helpers, Haml::Helpers, SimpleForm::ActionViewExtensions::FormHelper, Helpers::UtilsHelper
Defined in:
lib/ui_bibz/ui/core/navigations/components/toolbar_form.rb

Overview

Create a ToolbarForm

This element is an extend of ActionView::Helpers::FormHelper::FormFor to Rails

Attributes

  • content - Content of element

  • options - Options of element

  • html_options - Html Options of element

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for
# and
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag

Signatures

UiBibz::Ui::Core::Navigations::ToolbarForm.new(options = nil, html_options = nil) do |f|
  f.text_field :field
  f.submit 'Submit'
end

Examples

UiBibz::Ui::Core::Navigations::ToolbarForm.new(position: :right) do |f|
  f.text_field :field
  f.submit 'Submit'
end.render

UiBibz::Ui::Core::Navigations::ToolbarForm.new('/search', type: :form_tag) do
  text_field_tag :field
  submit_tag 'Submit'
end.render

Instance Attribute Summary collapse

Attributes inherited from Base

#output_buffer

Instance Method Summary collapse

Methods included from Helpers::UtilsHelper

#ui_form_for, #ui_translatize

Methods inherited from Base

#generate_id, #i18n_set?, #inject_url

Constructor Details

#initialize(model_or_url, options = {}, &block) ⇒ ToolbarForm

Returns a new instance of ToolbarForm.



51
52
53
54
55
56
57
# File 'lib/ui_bibz/ui/core/navigations/components/toolbar_form.rb', line 51

def initialize(model_or_url, options = {}, &block)
  init_haml_helpers
  @content      = block
  @model_or_url = model_or_url
  @options      = options
  @html_options = %i[form_for ui_form_for].exclude?(type) ? html_options_for_form(@model_or_url, new_option) : new_option
end

Instance Attribute Details

#html_optionsObject

Returns the value of attribute html_options.



49
50
51
# File 'lib/ui_bibz/ui/core/navigations/components/toolbar_form.rb', line 49

def html_options
  @html_options
end

Instance Method Details

#renderObject

Render html tag



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ui_bibz/ui/core/navigations/components/toolbar_form.rb', line 60

def render
  case type
  when :form_for
    @form = form_for(@model_or_url, html_options, &@content)
  when :ui_form_for
    begin
      @form = ui_form_for(@model_or_url, html_options, &@content)
    rescue e
      raise 'You must install simple form to use ui_form_for.'
    end
  else
    @form = form_tag_with_body(html_options, capture(&@content))
  end
end