SHARE
TWEET

Untitled

a guest May 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var app = {
  2.   error: false,
  3.   init: function () {
  4.  
  5.     var form = document.querySelector('#login-form');
  6.     form.addEventListener('submit', function (event) {
  7.       event.preventDefault();
  8.      
  9.       // Récupérer tous les champs du tableau
  10.       const fields = form.querySelectorAll('input');
  11.       inputs.forEach(function (input) {
  12.         this.validField(field);
  13.       }
  14.  
  15.       // Si pas d'erreur, envoyer
  16.       if (!this.error) {
  17.         form.submit();
  18.       }
  19.     });
  20.   },
  21.  
  22.   validField: function (field) {
  23.     if (field.value.length < 3) {
  24.       // Faire le traitement ici
  25.      
  26.       this.error = true;
  27.     }
  28.  
  29.     else {
  30.       this.error = false;
  31.     }
  32.   }
  33. };
  34.  
  35. document.addEventListener('DOMContentLoaded', app.init);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top