Ajoute des dates, et les enregistres dans le localStorage

This commit is contained in:
Yannick Francois 2018-11-27 23:55:54 +01:00
parent 531fd91aef
commit 8f309740c1
2 changed files with 35 additions and 15 deletions

View File

@ -35,17 +35,11 @@
<li>
<i class="far fa-calendar-alt"></i>
<input type="date" name="date-1">
<button class="btn-no-style"><i class="fas fa-trash-alt"></i></button>
</li>
<li class="item-disabled">
<i class="far fa-calendar-alt"></i>
<input type="date" name="date-2">
<button class="btn-no-style"><i class="fas fa-trash-alt"></i></button>
<button class="remove btn-no-style"><i class="fas fa-trash-alt"></i></button>
</li>
</ul>
<button>Ajouter une plage de date</button>
<button id="addDateButton">Ajouter une date</button>
</section>
<nav>

View File

@ -62,12 +62,6 @@ const buildTextField = () => {
}
$$('input').forEach((inputElement) => {
inputElement.addEventListener("change", () => {
localStorage[inputElement.name] = inputElement.value
});
});
if($("#add-response-choice")) {
$("#add-response-choice").addEventListener('click', (e) => {
e.preventDefault();
@ -101,10 +95,42 @@ if(document.getElementById("type_sondage")) {
}
if(document.getElementById("startButton")) {
startButton.addEventListener('click', function () {
startButton.addEventListener('click', () => {
localStorage.clear()
localStorage.setItem('type_sondage', 'classique');
});
}
if(document.getElementById("addDateButton")) {
addDateButton.addEventListener('click', () => {
let newLi = document.createElement("li")
let content = $("ul>li").innerHTML.replace("date-1", `date-${$$("li").length + 1}`)
newLi.innerHTML = content
$("ul").appendChild(newLi);
initEventOnScreen();
});
}
const addDeleteParentEvent = () => {
$$(".remove").forEach((element) => {
element.addEventListener('click', () => {
element.parentElement.remove();
});
});
}
const addInputToStorageEvent = () => {
$$('input').forEach((inputElement) => {
inputElement.addEventListener("change", () => {
localStorage[inputElement.name] = inputElement.value
});
});
}
const initEventOnScreen = () => {
addDeleteParentEvent();
addInputToStorageEvent();
}
initEventOnScreen();
debugStorage();