<h1>Match Columns</h1>
<form action="" method="post">{% csrf_token %}
    {{ formset.management_form }}
    
    <ul>
        {% for error in formset.errors %}
          <li>{{ error }}</li>
        {% endfor %}
    </ul>
    {% if errors %}
        <ul>
            {% for error in errors %}
                <li>{{ error }}</li>
            {% endfor %}
        </ul>
    {% endif %}
    <table>
        <tr>
            <th>Column Header</th>
            <th>Field</th>
            <th>Sample Data</th>
            <th>Default Value</th>
            {% if import_log.import_type == "U" or import_log.import_type == "O" %}
                <th>Update Key</th>
            {% endif %}
            <th>Clear field on blank cell</th>
        </tr>
        {% for form in formset %}
            <tr>
                <td>
                    {% if form.instance.column_name %}
                        {{ form.id.as_hidden }}
                        {{ form.instance.column_name }}
                    {% else %}
                        {{ form.column_name }}
                    {% endif %}
                    {{ form.column_name.as_hidden }} {{ form.column_name.error }}
                    {{ form.import_setting.as_hidden }} {{ form.import_setting.error }}
                </td>
                <td>
                    {{ form.field_name }} {{ form.field_name.error }}
                </td>
                <td>
                    {{ form.sample }}
                </td>
                <td>
                    {{ form.default_value }} {{ form.default_value.error }}
                </td>
                {% if import_log.import_type == "U" or import_log.import_type == "O" %}
                    <td>
                        <input name="update_key"
                               value="{% if form.instance.column_name %}{{ form.instance.column_name }}{% else %}{{ form.column_name }}{% endif %}"
                               type="radio"
                               {% if import_log.update_key == form.instance.column_name %}
                                   checked="checked"
                                {% endif %}
                               />
                    </td>
                {% endif %}
                <td>{{ form.null_on_empty }}</td>
            </tr>
        {% endfor %}
    </table>
    
    <input type="submit" value="Next"/>
</form>
