2015-12-10 09:56:35 +00:00
|
|
|
var crPrenom = document.getElementById('crPrenom');
|
2015-12-10 11:23:22 +00:00
|
|
|
var crNom = document.getElementById('crNom');
|
|
|
|
var sbCreer = document.getElementById('sbCreer');
|
2015-12-10 09:56:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* VERIFICATION DES SAISIES */
|
|
|
|
|
|
|
|
////////////
|
|
|
|
// PRENOM //
|
|
|
|
////////////
|
|
|
|
crPrenom.addEventListener('keyup', function(e){
|
|
|
|
if( /^([a-z]{3,45})$/i.test(crPrenom.value) ){ // si champ correct
|
|
|
|
addClass(crPrenom, 'validated');
|
|
|
|
remClass(crPrenom, 'invalid');
|
|
|
|
}else{
|
|
|
|
remClass(crPrenom, 'validated');
|
|
|
|
|
|
|
|
if( crPrenom.value.length <= 4 || crPrenom.value.length > 45 )
|
|
|
|
addClass(crPrenom, 'invalid');
|
|
|
|
else
|
|
|
|
remClass(crPrenom, 'invalid');
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
/////////
|
|
|
|
// NOM //
|
|
|
|
/////////
|
|
|
|
crNom.addEventListener('keyup', function(e){
|
|
|
|
if( /^([a-z]{3,45})$/i.test(crNom.value) ){ // si champ correct
|
|
|
|
addClass(crNom, 'validated');
|
|
|
|
remClass(crNom, 'invalid');
|
|
|
|
}else{
|
|
|
|
remClass(crNom, 'validated');
|
|
|
|
|
|
|
|
if( crNom.value.length <= 4 || crNom.value.length > 45 )
|
|
|
|
addClass(crNom, 'invalid');
|
|
|
|
else
|
|
|
|
remClass(crNom, 'invalid');
|
|
|
|
}
|
2015-12-10 11:23:22 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sbCreer.addEventListener('click', function(e){
|
|
|
|
e.preventDefault(); // on annule le submit()
|
|
|
|
|
|
|
|
var formElements = sbCreer.parentNode.children;
|
|
|
|
var checker = true;
|
|
|
|
|
|
|
|
// pour chaque <input type='text'> du formulaire (fils direct uniquement)
|
|
|
|
for( var i = 0 ; i < formElements.length ; i++ ){ if( formElements[i] instanceof HTMLInputElement && formElements[i].type == 'text' ){
|
|
|
|
// si le champ est requis (required)
|
|
|
|
if( formElements[i].required )
|
|
|
|
checker = checker && formElements[i].className.indexOf('validated') > -1; // TRUE => validé (niveau interface)
|
|
|
|
// si le champ n'est pas requis et pas vide, on le vide
|
|
|
|
else if( formElements[i].value != '' && formElements[i].className.indexOf('validated') < 0 ) // si incorrect et pas vide
|
|
|
|
formElements[i].value = ''; // on vide
|
|
|
|
}}
|
|
|
|
|
|
|
|
if( checker ) // si tout es ok uniquement, on submit()
|
|
|
|
sbCreer.parentNode.submit();
|
2015-12-10 09:56:35 +00:00
|
|
|
}, false);
|