lib/formalizer/form.rb
# Binds fields to a template
# * +fields+ - Hash of id => FormField object. Fields that do not exist in the form will be ignored.
# * Raises an error if a required field is not present in the fields param,
#   or if it is present but doesn't have a value.
Binds fields to a template
+fields+ - Hash of id => FormField object. Fields that do not exist in the form will be ignored.
Raises an error if a required field is not present in the fields param,
or if it is present but doesn't have a value.
Binds fields to a template + fields + - Hash of id = > FormField object . Fields that do not exist in the form will be ignored . Raises an error if a required field is not present in the fields param or if it is present but doesn ' t have a value .
def fill fields
      raise TypeError unless fields.is_a?(Hash)
      @html_template.css('formalizer').each do |html_field|
        field_id = html_field.attributes['id'].value
        form_field = fields[field_id.to_sym]
        if form_field.nil?
          required_attribute = html_field.attributes['required']
          field_required = !required_attribute.nil? && (required_attribute.value == '' || required_attribute.value == 'true')
          raise RequiredField, "field #{field_id} is required" if field_required
          next
        end
        html_field.content = form_field.value
      end
    end
def fill fields raise TypeError unless fields . is_a? ( Hash ) @html_template . css ( 'formalizer' ) . each do | html_field | field_id = html_field . attributes [ 'id' ] . value form_field = fields [ field_id . to_sym ] if form_field . nil? required_attribute = html_field . attributes [ 'required' ] field_required = ! required_attribute . nil? && ( required_attribute . value == '' || required_attribute . value == 'true' ) raise RequiredField , "field #{field_id} is required" if field_required next end html_field . content = form_field . value end end
Binds fields to a template
 +fields+ - Hash of id => FormField object.
Binds fields to a template + fields + - Hash of id = > FormField object .
# raising error if field is required but not found in fields param, otherwise skipping this field # field found in field params, so we don't care if it's required or not
fields
<not_specific>