Class: Occams::Content::Tag::Checkbox

Inherits:
Fragment show all
Defined in:
lib/occams/content/tags/checkbox.rb

Overview

Tag for boolean content that is going to be rendered using checkbox

{{ cms:checkbox identifier }}

Instance Attribute Summary

Attributes inherited from Fragment

#identifier, #namespace, #options, #renderable

Attributes inherited from Occams::Content::Tag

#context, #params, #source

Instance Method Summary collapse

Methods inherited from Fragment

#form_field_id, #fragment, #initialize, #render

Methods inherited from Occams::Content::Tag

#allow_erb?, #initialize, #nodes, #render

Constructor Details

This class inherits a constructor from Occams::Content::Tag::Fragment

Instance Method Details

#contentObject



7
8
9
# File 'lib/occams/content/tags/checkbox.rb', line 7

def content
  fragment.boolean
end

#form_field(object_name, view, index) {|input| ... } ⇒ Object

Yields:

  • (input)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/occams/content/tags/checkbox.rb', line 11

def form_field(object_name, view, index)
  name = "#{object_name}[fragments_attributes][#{index}][boolean]"

  input = view.(:div, class: 'form-check mt-2') do
    view.concat view.hidden_field_tag(name, '0', id: nil)

    options = { id: form_field_id, class: 'form-check-input position-static' }
    view.concat view.check_box_tag(name, '1', content.present?, options)
  end

  yield input
end