Class: Playbook::Forms::Builder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/playbook/forms/builder.rb,
lib/playbook/forms/builder/action_area.rb,
lib/playbook/forms/builder/select_field.rb,
lib/playbook/forms/builder/checkbox_field.rb,
lib/playbook/forms/builder/typeahead_field.rb,
lib/playbook/forms/builder/date_picker_field.rb,
lib/playbook/forms/builder/form_field_builder.rb,
lib/playbook/forms/builder/collection_select_field.rb

Defined Under Namespace

Classes: ActionArea, FormFieldBuilder

Instance Method Summary collapse

Instance Method Details

#actionsObject



23
24
25
26
27
28
# File 'lib/playbook/forms/builder.rb', line 23

def actions
  context = @template.respond_to?(:view_context) ? @template.view_context : @template
  context. :ol, class: "pb-form-actions" do
    yield ActionArea.new(@template, submit_default_value)
  end
end

#check_box(name, props: {}, **options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/playbook/forms/builder/checkbox_field.rb', line 6

def check_box(name, props: {}, **options)
  label_text = @template.label(@object_name, name) if props[:label] == true
  options[:required] = true if props[:required]
  props[:margin_bottom] = "sm"
  props[:form_spacing] = true

  checked_value = options[:checked_value]
  unchecked_value = options[:unchecked_value]
  options.delete(:checked_value)
  options.delete(:unchecked_value)

  input = super(name, options, checked_value, unchecked_value)

  if props[:label]
    @template.pb_rails("caption", props: { text: label_text, margin_bottom: "xs" }) +
      @template.pb_rails("checkbox", props: props) do
        input
      end
  else
    @template.pb_rails("checkbox", props: props) do
      input
    end
  end
end

#collection_select(name, collection, value_method, text_method, options = {}, html_options = {}, props: {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/playbook/forms/builder/collection_select_field.rb', line 6

def collection_select(name, collection, value_method, text_method, options = {}, html_options = {}, props: {})
  props[:label] = @template.label(@object_name, name) if props[:label] == true
  options[:skip_default_ids] = false unless options.key?(:skip_default_ids)
  options[:prompt] = props[:blank_selection] || ""
  html_options[:required] = "required" if props[:required]
  input = super(name, collection, value_method, text_method, options, html_options)

  @template.pb_rails("select", props: props) do
    input
  end
end

#date_picker(name, props: {}) ⇒ Object



6
7
8
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 'lib/playbook/forms/builder/date_picker_field.rb', line 6

def date_picker(name, props: {})
  prefix = @object_name
  html_attribute_name = "#{prefix}[#{name}]"
  html_id = "#{prefix}_#{name}"

  props[:label] = @template.label(@object_name, name) if props[:label] == true
  props[:label] = "Date Picker" if props[:label].nil?

  props[:name] = html_attribute_name
  props[:picker_id] = html_id

  input = text_field(
    name,
    autocomplete: "off",
    disabled: props[:disable_input],
    data: props[:input_data],
    aria: props[:input_aria],
    props: {
      error: props[:error],
      label: props[:hide_label] ? nil : props[:label],
      placeholder: props[:placeholder],
      required: props[:required],
    }
  )

  @template.pb_rails("date_picker", props: props) do
    input
  end
end

#select(name, choices = nil, options = {}, html_options = {}, props: {}, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/playbook/forms/builder/select_field.rb', line 6

def select(name, choices = nil, options = {}, html_options = {}, props: {}, &block)
  props[:label] = @template.label(@object_name, name) if props[:label] == true
  options[:skip_default_ids] = false unless options.key?(:skip_default_ids)
  options[:prompt] = props[:blank_selection] || ""
  html_options[:required] = "required" if props[:required]
  input = super(name, choices, options, html_options, &block)

  @template.pb_rails("select", props: props) do
    input
  end
end

#typeahead(name, _options = {}, _html_options = {}, props: {}) ⇒ Object



6
7
8
9
# File 'lib/playbook/forms/builder/typeahead_field.rb', line 6

def typeahead(name, _options = {}, _html_options = {}, props: {})
  props[:name] = name
  @template.pb_rails("typeahead", props: props)
end