2021-12-29 14:41:33 +01:00
{# -*- mode: jinja-html -*- #}
2021-12-24 10:59:02 +01:00
{% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block styles %}
{{super()}}
< link type = "text/css" rel = "stylesheet" href = "/ScoDoc/static/css/autosuggest_inquisitor.css" / >
< script src = "/ScoDoc/static/libjs/AutoSuggest.js" > < / script >
{% endblock %}
{% block app_content %}
2022-02-08 16:40:32 +01:00
< h1 > Envoyer une offre< / h1 >
2021-12-24 10:59:02 +01:00
< br >
< div class = "row" >
< div class = "col-md-4" >
2022-02-28 18:57:05 +01:00
< p >
(*) champs requis
< / p >
2022-04-05 23:01:38 +02:00
< form method = "POST" action = "" novalidate >
{{ form.hidden_tag() }}
{{ form.responsables.label }}< br >
{% for subfield in form.responsables %}
{% if subfield.errors %}
{% for error in subfield.errors %}
2022-04-07 02:54:11 +02:00
< p class = "help-block form-error" > {{ error }}< / p >
2022-04-05 23:01:38 +02:00
{% endfor %}
{% endif %}
{% endfor %}
{{ form.responsables }}
2022-04-07 02:54:11 +02:00
< div style = "margin-bottom: 10px;" >
< button class = "btn btn-default" id = "add-responsable-field" > Ajouter un responsable< / button >
< input class = "btn btn-default" type = "submit" value = "Envoyer" >
< / div >
2022-04-05 23:01:38 +02:00
< / form >
2021-12-24 10:59:02 +01:00
< / div >
< / div >
2022-01-31 18:22:54 +01:00
2021-12-24 10:59:02 +01:00
< script >
2022-04-26 20:21:56 +02:00
let allResponsablesFieldWrapper = document.getElementById('responsables');
let allResponsablesField = allResponsablesFieldWrapper.getElementsByTagName('li');
for(let i = 0; i < allResponsablesField.length ; i + + ) {
let form_id = allResponsablesField[i].getElementsByTagName('input')[0].id
if(form_id.split('-')[1] != 0)
allResponsablesField[i].insertAdjacentHTML('beforeend', `< div class = "btn btn-default btn-remove" onclick = "deleteForm('${form_id}')" > Retirer< / div > `)
}
2021-12-24 10:59:02 +01:00
window.onload = function(e) {
var responsables_options = {
script: "/ScoDoc/entreprises/responsables?",
varname: "term",
json: true,
noresults: "Valeur invalide !",
minchars: 2,
timeout: 60000
};
2022-04-05 23:01:38 +02:00
let allResponsablesFieldWrapper = document.getElementById('responsables');
let allResponsablesField = allResponsablesFieldWrapper.getElementsByTagName('input');
for(let i = 0; i < allResponsablesField.length ; i + + ) {
new bsn.AutoSuggest(allResponsablesField[i].id, responsables_options);
}
let addResponsableFieldBtn = document.getElementById('add-responsable-field');
addResponsableFieldBtn.addEventListener('click', function(e){
e.preventDefault();
let allResponsablesFieldWrapper = document.getElementById('responsables');
let allResponsablesField = allResponsablesFieldWrapper.getElementsByTagName('input');
let responsableInputIds = []
for(let i = 0; i < allResponsablesField.length ; i + + ) {
responsableInputIds.push(parseInt(allResponsablesField[i].name.split('-')[1]));
}
let newFieldName = `responsables-${Math.max(...responsableInputIds) + 1}`;
allResponsablesFieldWrapper.insertAdjacentHTML('beforeend',`
2022-04-26 20:21:56 +02:00
< li > < label for = "${newFieldName}" > Responsable (*)< / label > < input class = "form-control" id = "${newFieldName}" name = "${newFieldName}" type = "text" value = "" placeholder = "Tapez le nom du responsable de formation" > < div class = "btn btn-default btn-remove" onclick = "deleteForm('${newFieldName}')" > Retirer< / div > < / li >
2022-04-05 23:01:38 +02:00
`);
var as_r = new bsn.AutoSuggest(newFieldName, responsables_options);
});
2021-12-24 10:59:02 +01:00
}
2022-04-26 20:21:56 +02:00
function deleteForm(x) {
var li_form = document.querySelector(`label[for=${x}]`).closest('li');
if (li_form) {
li_form.remove()
}
}
2021-12-24 10:59:02 +01:00
< / script >
{% endblock %}