{% extends "forms.html" %}
{% load forms %}


{% block title %}Edit Institute{% endblock %}


{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href='{% url "index" %}'>Home</a>&nbsp;›
    <a href="{% url 'kg_institute_list' %}">Institutes</a>&nbsp;›
    {% if institute %}
        <a href="{% url 'kg_institute_detail' institute.pk %}">{{ institute }}</a>&nbsp;›
        Edit
    {% else %}
        Create Institute
    {% endif %}
</div>
{% endblock %}


{% block content %}
{% if form.errors or delegate_formset.errors %}
<p class="errornote">
    Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}

<form method="post" action=".">{% csrf_token %}
    {{ delegate_formset.management_form }}
    <fieldset class="module aligned ()">
        <h2>Details</h2>
        {% form_as_div form %}
    </fieldset>
    <fieldset class="module aligned ()">
        <h2>Delegates</h2>
        {% for dform in delegate_formset.forms %}
        {{ dform.id }}
        {% inlineformfield dform.person dform.send_email dform.DELETE %}
        {% endfor %}
    </fieldset>

    <div class="submit-row">
        <input type="submit" value="Save" class="default" />
    </div>
</form>

<script type="text/javascript">
$(document).ready(function(){
    var name = $("#id_name");
    var lastValue = name.val();
    name.on('change keyup paste mouseup', function() {
        if (name.val() != lastValue) {
            lastValue = name.val();
            var newValue = lastValue.split(" ").join("").toLowerCase();
            $("#id_group_name").val(newValue)
        }
    })
})
</script>
{% endblock %}
