{% extends "webpage/base.html" %}

{% block Titel %}Create Label{% endblock %}
{% block scriptHeader %}
{% include 'autocomplete_light/static.html' %}
{% endblock %}
{% block content %}

<div class="card card-default">
    <div class="card-heading">
    	<h3>Create</h3>
    </div>
    <div class="card-body">
    	{% load crispy_forms_tags %}
    	{% csrf_token %}
    	{% crispy form %}
        {% if instance %}
            <a class ="btn btn-danger btn-sm" href="{% url 'labels:label_delete' pk=instance.id %}">delete</a>
        {% endif %}
    </div>
</div>
{% endblock %}
{% block scripts %}
{{ block.super }}
<script>
    // Script to parse the autocomplete input and to subsitute the entered string (fetched via autocomplete) through this part of the fetched string, which should be stored in the db. 
    $( "#submit-id-submit" ).click(function() {
        var dataToChange = $( "#id_isoCode").val().split("|");
        console.log(dataToChange.length);
        console.log(dataToChange);
        if(dataToChange.length === 2){
            console.log("dataToChange");
            $( "#id_isoCode").val(dataToChange[1]);
        }             
});
</script>

{% endblock %}
