Class: Formulary::HtmlForm::Fields::Field
- Inherits:
-
Object
- Object
- Formulary::HtmlForm::Fields::Field
show all
- Defined in:
- lib/formulary/html_form/fields/field.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(html_form, element) ⇒ Field
Returns a new instance of Field.
7
8
9
|
# File 'lib/formulary/html_form/fields/field.rb', line 7
def initialize(html_form, element)
@html_form, @element = html_form, element
end
|
Class Method Details
.supports_required? ⇒ Boolean
3
4
5
|
# File 'lib/formulary/html_form/fields/field.rb', line 3
def self.supports_required?
false
end
|
Instance Method Details
#error ⇒ Object
23
24
25
|
# File 'lib/formulary/html_form/fields/field.rb', line 23
def error
return "'#{label}' is required" if supports_required? && !presence_correct?
end
|
#label ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/formulary/html_form/fields/field.rb', line 27
def label
@label ||= \
begin
l = @html_form.label_for_field(name)
if l.nil? then nil
elsif l.is_a?(String) then l
else l["fieldset"]
end
end
end
|
#name ⇒ Object
11
12
13
|
# File 'lib/formulary/html_form/fields/field.rb', line 11
def name
@element.attributes["name"].value
end
|
#set_value(value) ⇒ Object
15
16
17
|
# File 'lib/formulary/html_form/fields/field.rb', line 15
def set_value(value)
@value = value
end
|
#valid? ⇒ Boolean
19
20
21
|
# File 'lib/formulary/html_form/fields/field.rb', line 19
def valid?
supports_required? && presence_correct?
end
|