Class: DryCrud::Form::Control

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(builder, attr, *args) ⇒ 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.extract_options!
  @args = args

  @addon = options.delete(:addon)
  @help = options.delete(:help)
  @span = options.delete(:span)
  @caption = options.delete(:caption)
  @field_method = options.delete(:field_method)
  @required = options[:required]
end

Instance Attribute Details

#addonObject (readonly)

Returns the value of attribute addon


9
10
11
# File 'app/helpers/dry_crud/form/control.rb', line 9

def addon
  @addon
end

#argsObject (readonly)

Returns the value of attribute args


9
10
11
# File 'app/helpers/dry_crud/form/control.rb', line 9

def args
  @args
end

#attrObject (readonly)

Returns the value of attribute attr


9
10
11
# File 'app/helpers/dry_crud/form/control.rb', line 9

def attr
  @attr
end

#builderObject (readonly)

Returns the value of attribute builder


9
10
11
# File 'app/helpers/dry_crud/form/control.rb', line 9

def builder
  @builder
end

#helpObject (readonly)

Returns the value of attribute help


9
10
11
# File 'app/helpers/dry_crud/form/control.rb', line 9

def help
  @help
end

#optionsObject (readonly)

Returns the value of attribute options


9
10
11
# File 'app/helpers/dry_crud/form/control.rb', line 9

def options
  @options
end

Instance Method Details

#render_contentObject

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