SumOfUs/Champaign

View on GitHub
app/views/forms/_preview.html.slim

Summary

Maintainability
Test Coverage
form
  - form.form_elements.each do |element|
    .form-element.form-group.clearfix
      - label = "#{element.label}#{element.required ? '*' : ''}"
      - case element.data_type
      - when 'text', 'email', 'phone', 'postal'
        input.form-control placeholder=label value=element.default_value
      - when 'country'
        = select_tag '', options_for_select(ISO3166::Country.all_names_with_codes, element.default_value), class: "form-control"
      - when 'dropdown'
        = element.label
        - options = element.formatted_choices.map { |c| [c[:label], c[:value]] }
        = select_tag '', options_for_select(options, element.default_value), class: "form-control"
      - when 'hidden'
        - tag_explanation = "Hidden tag: #{element.name}."
        - tag_explanation += " Default value: #{element.default_value}" unless element.default_value.blank?
        i = tag_explanation
      - when 'paragraph'
        textarea.form-control placeholder=label
          = element.default_value
      - when 'choice'
        = label
        - element.formatted_choices.each do |choice|
          label.radio for="#{choice[:id]}"
            input type="radio" value="#{choice[:value]}" name="#{element.name}" id="#{choice[:id]}"
            = choice[:label]
      - when 'instruction'
        = element.label.html_safe
      - when 'checkbox'
        = check_box_tag element.name, 1, element.default_value.present?
        ' 
        = label