Browse Source

impossible de valider le formulaire si aucune checkbox n'est cochée

master
n0m1s 10 years ago
parent
commit
5d7e157aee
1 changed files with 18 additions and 1 deletions
  1. +18
    -1
      addEvent.php

+ 18
- 1
addEvent.php View File

@ -119,7 +119,7 @@ Supprimer l'évènement !</a>
{ {
?> ?>
<div class="categorie_grp"> <div class="categorie_grp">
<input type="checkbox" name="checkbox-cat-<?php echo $cat[0]; ?>" id="checkbox-cat-<?php echo $cat[0]; ?>" <?php echo (is_array($defaults['categories']) && in_array($cat[0], $defaults['categories']))? 'checked' : '';?> />
<input type="checkbox" class="checkbox-cat" name="checkbox-cat-<?php echo $cat[0]; ?>" id="checkbox-cat-<?php echo $cat[0]; ?>" <?php echo (is_array($defaults['categories']) && in_array($cat[0], $defaults['categories']))? 'checked' : '';?> />
<label for="checkbox-cat-<?php echo $cat[0]; ?>"><?php echo htmlentities($cat[1]); ?></label> <label for="checkbox-cat-<?php echo $cat[0]; ?>"><?php echo htmlentities($cat[1]); ?></label>
</div> </div>
<?php <?php
@ -232,5 +232,22 @@ Supprimer l'évènement !</a>
</body> </body>
<script type="text/javascript"> <script type="text/javascript">
//TODO: check form before sending //TODO: check form before sending
function checkCheckboxes()
{
var checkboxes = document.getElementsByClassName("checkbox-cat");
for(var i = 0; i < checkboxes.length; ++i)
{
console.log(checkboxes[i].name);
if(checkboxes[i].checked)
return true;
}
return false;
}
document.getElementById('eventForm').addEventListener('submit', function(e) {
if(!checkCheckboxes())
e.preventDefault();
});
</script> </script>
</html> </html>

Loading…
Cancel
Save