{% extends "base_table.html" %}

{% block inner_content %}
  <h3>Update row {{ table_pk|pk_display(pk) }} in {{ table }}
    <input id="toggle-checkboxes" type="checkbox" />
  </h3>
  <form action="{{ url_for('table_update', table=table, pk=pk) }}" method="post" role="form">
    {% for column in columns %}
      <div class="form-group row">
        <label for="id_{{ column.name }}" class="col-sm-2 col-form-label">{{ column.name }}</label>
        <div class="col-sm-10">
          <div class="input-group">
            <div class="input-group-prepend">
              <div class="input-group-text">
                <input {% if column.name in edited %}checked {% endif %}class="chk-enable-column" data-target-element="id_{{ column.name }}" type="checkbox" name="chk_{{ column.name }}" aria-label="Allow updating this column.">
              </div>
            </div>
            {% if column.data_type.lower() in ('text', 'blob') %}
              <textarea class="form-control{% if column.name in errors %} is-invalid{% endif %}" {% if column.name not in edited %}disabled {% endif %} id="id_{{ column.name }}" name="{{ column.name }}">{% if row[column.name] == None %}NULL{% else %}{{ row[column.name] }}{% endif %}</textarea>
            {% else %}
              <input class="form-control{% if column.name in errors %} is-invalid{% endif %}" {% if column.name not in edited %}disabled {% endif %} id="id_{{ column.name }}" name="{{ column.name }}" value="{% if row[column.name] == None %}NULL{% else %}{{ row[column.name] }}{% endif %}" />
            {% endif %}
            {% if column.name in errors %}
              <div class="invalid-feedback">{{ errors[column.name] }}</div>
            {% endif %}
          </div>
          <small class="form-text text-muted">
            {% if column.primary_key %}
              <strong>Primary key.</strong>
            {% endif %}
            {{ column.data_type|default('ANY') }}{% if not column.null %} NOT NULL{% endif %}
            {% if column.default %}(default {{ column.default }}{% endif %}
          </small>
        </div>
      </div>
    {% endfor %}
    <button class="btn btn-primary" type="submit">Update</button>
    <a class="btn btn-secondary" href="{{ url_for('table_content', table=table) }}">Cancel</a>
  </form>
{% endblock %}
