Browse Source

se souvient des valeurs du formulaire en js

master
vince vince 3 years ago
parent
commit
121ec02f3b
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      index.php

+ 21
- 1
index.php View File

@ -340,7 +340,7 @@ if (!$isConfig and $hasSupplier) {
</section>
<section class="container-fluid">
<div class="row g-3">
<form action="<?php printf('%s?supplier=%s', $requestUrl, $supplier); ?>" method="post">
<form class="js-localremember" action="<?php printf('%s?supplier=%s', $requestUrl, $supplier); ?>" method="post">
<div class="row mb-3">
<label for="title" class="col-sm-2 col-form-label">Nom</label>
<div class="col-sm-10">
@ -442,5 +442,25 @@ if (!$isConfig and $hasSupplier) {
});
</script>
<?php endif; ?>
<script>
document.querySelectorAll('.js-localremember').forEach(function (form) {
const fields = [ 'name', 'choice' ];
form.addEventListener('submit', function (event) {
fields.forEach(function (field) {
window.localStorage.setItem('mon_panier_bio_' + field, form.elements[field].value);
});
});
fields.forEach(function (field) {
if (
(form.elements[field].value === '')
&& (window.localStorage.getItem('mon_panier_bio_' + field) !== null)
) {
form.elements[field].value = window.localStorage.getItem('mon_panier_bio_' + field);
}
});
});
</script>
</body>
</html>

Loading…
Cancel
Save