{% extends 'base.html' %}
{% block body %}

{% block form required %}
{% endblock %}
<script>
function setFormData(field_id, value) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '{{ base_url }}/submit/' + field_id);
    xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
    xhr.send(JSON.stringify(value));
}

const debounce = (callback, wait) => {
  let timeoutId = null;
  return (...args) => {
    window.clearTimeout(timeoutId);
    timeoutId = window.setTimeout(() => {
      callback(...args);
    }, wait);
  };
}

const submit = debounce(setFormData, 500)
</script>
{% endblock %}