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
32
33
34
|
# File 'lib/formulary/html_form/fields/field.rb', line 32
def error
return "'#{label}' is required" if supports_required? && !presence_correct?
end
|
#get_value_from_data_field(data_field) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/formulary/html_form/fields/field.rb', line 15
def get_value_from_data_field(data_field)
find_first_element_with_data_field(data_field) if @element.blank? && @elements
unless @element.blank?
@element.attributes.include?(data_field) ? @element.attributes[data_field].value : nil
else
nil
end
end
|
#is_hidden? ⇒ Boolean
48
49
50
|
# File 'lib/formulary/html_form/fields/field.rb', line 48
def is_hidden?
self.class.compatible_type == "hidden" rescue false
end
|
#label ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/formulary/html_form/fields/field.rb', line 36
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
24
25
26
|
# File 'lib/formulary/html_form/fields/field.rb', line 24
def set_value(value)
@value = value
end
|
#valid? ⇒ Boolean
28
29
30
|
# File 'lib/formulary/html_form/fields/field.rb', line 28
def valid?
supports_required? && presence_correct?
end
|