class Formulary::HtmlForm::Fields::Field
Public Class Methods
new(html_form, element)
click to toggle source
# File lib/formulary/html_form/fields/field.rb, line 7 def initialize(html_form, element) @html_form, @element = html_form, element end
supports_required?()
click to toggle source
# File lib/formulary/html_form/fields/field.rb, line 3 def self.supports_required? false end
Public Instance Methods
error()
click to toggle source
# 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)
click to toggle source
# 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
label()
click to toggle source
# 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()
click to toggle source
# File lib/formulary/html_form/fields/field.rb, line 11 def name @element.attributes["name"].value end
set_value(value)
click to toggle source
# File lib/formulary/html_form/fields/field.rb, line 24 def set_value(value) @value = value end
valid?()
click to toggle source
# File lib/formulary/html_form/fields/field.rb, line 28 def valid? supports_required? && presence_correct? end
Protected Instance Methods
find_first_element_with_data_field(data_field)
click to toggle source
# File lib/formulary/html_form/fields/field.rb, line 54 def find_first_element_with_data_field(data_field) @elements.each do |e| if e.attributes.include?(data_field) @element = e return end end end
presence_correct?()
click to toggle source
# File lib/formulary/html_form/fields/field.rb, line 67 def presence_correct? if required? && @value.blank? return false else return true end end
required?()
click to toggle source
# File lib/formulary/html_form/fields/field.rb, line 75 def required? @element.attributes.include?("required") end
supports_required?()
click to toggle source
# File lib/formulary/html_form/fields/field.rb, line 63 def supports_required? self.class.supports_required? end