Class: DryCrud::Form::Control
- Inherits:
-
Object
- Object
- DryCrud::Form::Control
- Defined in:
- app/helpers/dry_crud/form/control.rb
Overview
Internal class to handle the rendering of a single form control, consisting of a label, input field, addon, help text or required mark.
Constant Summary collapse
- REQUIRED_MARK =
Html displayed to mark an input as required.
'*'.freeze
- INPUT_SPANS =
Number of default input field span columns depending on the #field_method.
Hash.new(8)
Instance Attribute Summary collapse
-
#addon ⇒ Object
readonly
Returns the value of attribute addon.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#attr ⇒ Object
readonly
Returns the value of attribute attr.
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#help ⇒ Object
readonly
Returns the value of attribute help.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(builder, attr, *args, **options) ⇒ Control
constructor
Create a new control instance.
-
#render_content ⇒ Object
Renders only the content of the control.
-
#render_labeled(content = nil) ⇒ Object
Renders the complete control with label and everything.
Constructor Details
#initialize(builder, attr, *args, **options) ⇒ Control
Create a new control instance. Takes the form builder, the attribute to build the control for as well as any additional arguments for the field method. This includes an options hash as the last argument, that may contain the following special options:
-
:addon
- Addon content displayed just after the input field. -
:help
- A help text displayed below the input field. -
:span
- Number of columns the input field should span. -
:caption
- Different caption for the label. -
:field_method
- Different method to create the input field. -
:required
- Sets the field as required (The value for this option usually is ‘required’).
All the other options will go to the field_method.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/dry_crud/form/control.rb', line 42 def initialize(builder, attr, *args, **) @builder = builder @attr = attr @options = @args = args @addon = .delete(:addon) @help = .delete(:help) @span = .delete(:span) @caption = .delete(:caption) @field_method = .delete(:field_method) @required = [:required] end |
Instance Attribute Details
#addon ⇒ Object (readonly)
Returns the value of attribute addon.
9 10 11 |
# File 'app/helpers/dry_crud/form/control.rb', line 9 def addon @addon end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
9 10 11 |
# File 'app/helpers/dry_crud/form/control.rb', line 9 def args @args end |
#attr ⇒ Object (readonly)
Returns the value of attribute attr.
9 10 11 |
# File 'app/helpers/dry_crud/form/control.rb', line 9 def attr @attr end |
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
9 10 11 |
# File 'app/helpers/dry_crud/form/control.rb', line 9 def builder @builder end |
#help ⇒ Object (readonly)
Returns the value of attribute help.
9 10 11 |
# File 'app/helpers/dry_crud/form/control.rb', line 9 def help @help end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'app/helpers/dry_crud/form/control.rb', line 9 def @options end |
Instance Method Details
#render_content ⇒ Object
Renders only the content of the control. I.e. no label and span divs.
58 59 60 |
# File 'app/helpers/dry_crud/form/control.rb', line 58 def render_content content end |
#render_labeled(content = nil) ⇒ Object
Renders the complete control with label and everything. Render the content given or the default one.
64 65 66 67 |
# File 'app/helpers/dry_crud/form/control.rb', line 64 def render_labeled(content = nil) @content = content if content labeled end |