Added error message under the missing/invalid field (user/machine/group::create/edit)

This commit is contained in:
xdrm-brackets 2017-09-18 18:32:39 +02:00
parent 2b698e56f5
commit 5368fe4edf
6 changed files with 138 additions and 29 deletions

View File

@ -82,6 +82,7 @@
echo "<form class='valid'>"; echo "<form class='valid'>";
echo "<input id='create_name' type='text' placeholder='Nom'><br>"; echo "<input id='create_name' type='text' placeholder='Nom'><br>";
echo "<span class='error-msg create_name'></span><br>";
echo "<select id='create_class'> echo "<select id='create_class'>
<option value='-' selected disabled>Type de groupe</option> <option value='-' selected disabled>Type de groupe</option>
@ -89,6 +90,8 @@
<option value='1'>machines</option> <option value='1'>machines</option>
</select>"; </select>";
echo "<span class='error-msg create_class'></span><br>";
echo "<button id='create_submit'>Créer</button>"; echo "<button id='create_submit'>Créer</button>";
echo "</form>"; echo "</form>";
@ -115,7 +118,7 @@
echo "<input id='remove_search_id' type='hidden' value=''>"; echo "<input id='remove_search_id' type='hidden' value=''>";
// Indice du resultat // Indice du resultat
echo "<span class='remove_search_view'>groupe <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>"; echo "<span class='remove_search_view'>groupe <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>";
echo "<button id='remove_search_submit' class='search'>Trouver</button><br>"; echo "<button id='remove_search_submit' class='search'>Trouver/Suivant</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>"; echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
@ -148,11 +151,13 @@
echo "<input id='edit_search_id' type='hidden' value=''>"; echo "<input id='edit_search_id' type='hidden' value=''>";
// Indice du resultat // Indice du resultat
echo "<span class='edit_search_view'>groupe <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>"; echo "<span class='edit_search_view'>groupe <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>";
echo "<button id='edit_search_submit' class='search'>Trouver</button><br>"; echo "<button id='edit_search_submit' class='search'>Trouver/Suivant</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>"; echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
echo "<input id='edit_name' type='text' placeholder='Nom'><br>"; echo "<input id='edit_name' type='text' placeholder='Nom'><br>";
echo "<span class='error-msg edit_name'></span><br>";
echo "<input id='edit_class' type='text' placeholder='Type de groupe' disabled><br>"; echo "<input id='edit_class' type='text' placeholder='Type de groupe' disabled><br>";
echo "<button id='edit_submit' disabled>Modifier</button>"; echo "<button id='edit_submit' disabled>Modifier</button>";
echo "</form>"; echo "</form>";

View File

@ -319,7 +319,13 @@ if( section.create.element != null ){
name: document.querySelector(section.create.text + '#create_name'), name: document.querySelector(section.create.text + '#create_name'),
class: document.querySelector(section.create.text + '#create_class'), class: document.querySelector(section.create.text + '#create_class'),
submit: document.querySelector(section.create.text + '#create_submit') submit: document.querySelector(section.create.text + '#create_submit')
} };
// On recupere tous les messages d'erreur
section.create.errmsg = {
name: document.querySelector(section.create.text + '.error-msg.create_name'),
class: document.querySelector(section.create.text + '.error-msg.create_class')
};
/* (n) Gestion de l'envoi du formulaire */ /* (n) Gestion de l'envoi du formulaire */
@ -327,6 +333,10 @@ if( section.create.element != null ){
// On annule l'envoi de base (PHP) // On annule l'envoi de base (PHP)
e.preventDefault(); e.preventDefault();
// On vide les messages erreurs
section.create.errmsg.name.innerHTML =
section.create.errmsg.class.innerHTML = '';
var request = { var request = {
path: 'clusterDefault/create', // On veut creer un utilisateur path: 'clusterDefault/create', // On veut creer un utilisateur
name: section.create.input.name.value, name: section.create.input.name.value,
@ -334,6 +344,7 @@ if( section.create.element != null ){
}; };
api.send(request, function(answer){ api.send(request, function(answer){
if( answer.error == 0 ){ // Tout s'est bien deroule if( answer.error == 0 ){ // Tout s'est bien deroule
console.log('Groupe cree!'); console.log('Groupe cree!');
@ -342,6 +353,15 @@ if( section.create.element != null ){
// On vide les champs // On vide les champs
section.create.input.name.value = ''; section.create.input.name.value = '';
section.create.input.class.children[0].selected = 'selected'; section.create.input.class.children[0].selected = 'selected';
}else{ // Erreur
console.error('ModuleError::'+answer.error);
// if missing or incorrect param
if( answer.error == 16 || answer.error == 17 ){
if( section.create.errmsg[answer.ErrorArguments[0]] != null )
section.create.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
}
} }
}); });
@ -603,6 +623,11 @@ if( section.edit.element != null ){
submit: document.querySelector(section.edit.text + '#edit_submit') submit: document.querySelector(section.edit.text + '#edit_submit')
}; };
// On recupere tous les messages d'erreur
section.edit.errmsg = {
name: document.querySelector(section.edit.text + '.error-msg.edit_name')
};
var lastkeywords_edit = ''; var lastkeywords_edit = '';
var found_edit = []; var found_edit = [];
var searchindex_edit = 0; var searchindex_edit = 0;
@ -742,6 +767,9 @@ if( section.edit.element != null ){
// On annule l'envoi de base (PHP) // On annule l'envoi de base (PHP)
e.preventDefault(); e.preventDefault();
// On vide les messages erreurs
section.edit.errmsg.name.innerHTML = '';
// Si l'id est defini // Si l'id est defini
if( section.edit.input.search.id.value != '' ){ if( section.edit.input.search.id.value != '' ){
@ -779,8 +807,16 @@ if( section.edit.element != null ){
}); });
}else // Erreur }else{ // Erreur
console.error('ModuleError::'+answer.error); console.error('ModuleError::'+answer.error);
// if missing or incorrect param
if( answer.error == 16 || answer.error == 17 ){
if( section.edit.errmsg[answer.ErrorArguments[0]] != null )
section.edit.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
}
}
}); });
} }

View File

@ -302,7 +302,12 @@ if( section.create.element != null ){
section.create.input = { section.create.input = {
name: document.querySelector(section.create.text + '#create_name'), name: document.querySelector(section.create.text + '#create_name'),
submit: document.querySelector(section.create.text + '#create_submit') submit: document.querySelector(section.create.text + '#create_submit')
} };
// On recupere tous les messages d'erreur
section.create.errmsg = {
name: document.querySelector(section.create.text + '.error-msg.create_name')
};
/* (2) Gestion de l'envoi du formulaire */ /* (2) Gestion de l'envoi du formulaire */
@ -310,6 +315,9 @@ if( section.create.element != null ){
// On annule l'envoi de base (PHP) // On annule l'envoi de base (PHP)
e.preventDefault(); e.preventDefault();
// On vide les messages erreurs
section.create.errmsg.name.innerHTML = '';
/* (3) On rédige la requête */ /* (3) On rédige la requête */
var request = { var request = {
path: 'machineDefault/create', // On veut creer un utilisateur path: 'machineDefault/create', // On veut creer un utilisateur
@ -326,6 +334,17 @@ if( section.create.element != null ){
section.create.input.submit.anim('active', 1500); section.create.input.submit.anim('active', 1500);
}else{ // Erreur
console.error('ModuleError::'+answer.error);
// if missing or incorrect param
if( answer.error == 16 || answer.error == 17 ){
if( section.create.errmsg[answer.ErrorArguments[0]] != null )
section.create.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
}
} }
}); });
@ -567,6 +586,11 @@ if( section.edit.element != null ){
submit: document.querySelector(section.edit.text + '#edit_submit') submit: document.querySelector(section.edit.text + '#edit_submit')
}; };
// On recupere tous les messages d'erreur
section.edit.errmsg = {
name: document.querySelector(section.edit.text + '.error-msg.edit_name')
};
var lastkeywords_edit = ''; var lastkeywords_edit = '';
var found_edit = []; var found_edit = [];
var searchindex_edit = 0; var searchindex_edit = 0;
@ -629,7 +653,6 @@ if( section.edit.element != null ){
// On annule l'envoi de base (PHP) // On annule l'envoi de base (PHP)
e.preventDefault(); e.preventDefault();
/* (1) Si le champ n'est pas vide */ /* (1) Si le champ n'est pas vide */
if( section.edit.input.search.keyword.value != '' ){ if( section.edit.input.search.keyword.value != '' ){
@ -687,6 +710,9 @@ if( section.edit.element != null ){
// On annule l'envoi de base (PHP) // On annule l'envoi de base (PHP)
e.preventDefault(); e.preventDefault();
// On vide les messages erreurs
section.edit.errmsg.name.innerHTML = '';
// Si l'id est defini // Si l'id est defini
if( section.edit.input.search.id.value != '' ){ if( section.edit.input.search.id.value != '' ){
@ -714,8 +740,16 @@ if( section.edit.element != null ){
} }
}); });
}else // Erreur }else{ // Erreur
console.error('ModuleError::'+answer.error); console.error('ModuleError::'+answer.error);
// if missing or incorrect param
if( answer.error == 16 || answer.error == 17 ){
if( section.edit.errmsg[answer.ErrorArguments[0]] != null )
section.edit.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
}
}
}); });
} }

View File

@ -340,6 +340,7 @@ if( section.create.element != null ){
// On annule l'envoi de base (PHP) // On annule l'envoi de base (PHP)
e.preventDefault(); e.preventDefault();
// On vide les messages erreurs
section.create.errmsg.code.innerHTML = section.create.errmsg.code.innerHTML =
section.create.errmsg.username.innerHTML = section.create.errmsg.username.innerHTML =
section.create.errmsg.firstname.innerHTML = section.create.errmsg.firstname.innerHTML =
@ -370,8 +371,12 @@ if( section.create.element != null ){
}else{ // Erreur }else{ // Erreur
console.error('ModuleError::'+answer.error); console.error('ModuleError::'+answer.error);
if( /^[^']*'(\w+)'/i.test(answer.ErrorDescription) )
section.create.errmsg[RegExp.$1].innerHTML = 'Champ manquant ou erronné.'; // if missing or incorrect param
if( answer.error == 16 || answer.error == 17 ){
if( section.create.errmsg[answer.ErrorArguments[0]] != null )
section.create.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
}
} }
}); });
@ -516,6 +521,7 @@ if( section.remove.element != null ){
autofill_remove(); autofill_remove();
} }
// On met à jour la dernière recherche // On met à jour la dernière recherche
lastkeywords_remove = getUsers.keywords; lastkeywords_remove = getUsers.keywords;
}); });
@ -579,6 +585,8 @@ if( section.remove.element != null ){
}else // Erreur }else // Erreur
console.error('ModuleError::'+answer.error); console.error('ModuleError::'+answer.error);
}); });
} }
@ -625,6 +633,15 @@ if( section.edit.element != null ){
submit: document.querySelector(section.edit.text + '#edit_submit') submit: document.querySelector(section.edit.text + '#edit_submit')
}; };
// On recupere tous les messages d'erreur
section.edit.errmsg = {
code: document.querySelector(section.edit.text + '.error-msg.edit_code'),
username: document.querySelector(section.edit.text + '.error-msg.edit_username'),
firstname: document.querySelector(section.edit.text + '.error-msg.edit_firstname'),
lastname: document.querySelector(section.edit.text + '.error-msg.edit_lastname'),
mail: document.querySelector(section.edit.text + '.error-msg.edit_mail')
};
/* (1) Gestion du code RFID */ /* (1) Gestion du code RFID */
createChecker.append( section.edit.input.code, format_code, '01-AB-CD-23'); createChecker.append( section.edit.input.code, format_code, '01-AB-CD-23');
section.edit.input.code.addEventListener('keyup', function(e){ section.edit.input.code.addEventListener('keyup', function(e){
@ -761,6 +778,13 @@ if( section.edit.element != null ){
// On annule l'envoi de base (PHP) // On annule l'envoi de base (PHP)
e.preventDefault(); e.preventDefault();
// On vide les messages erreurs
section.edit.errmsg.code.innerHTML =
section.edit.errmsg.username.innerHTML =
section.edit.errmsg.firstname.innerHTML =
section.edit.errmsg.lastname.innerHTML =
section.edit.errmsg.mail.innerHTML = '';
// Si l'id est defini // Si l'id est defini
if( section.edit.input.search.id.value != '' ){ if( section.edit.input.search.id.value != '' ){
@ -793,8 +817,16 @@ if( section.edit.element != null ){
}); });
}else // Erreur }else{ // Erreur
console.error('ModuleError::'+answer.error); console.error('ModuleError::'+answer.error);
// if missing or incorrect param
if( answer.error == 16 || answer.error == 17 ){
if( section.edit.errmsg[answer.ErrorArguments[0]] != null )
section.edit.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
}
}
}); });
} }

View File

@ -71,6 +71,7 @@
echo "<form class='valid'>"; echo "<form class='valid'>";
echo "<input id='create_name' type='text' placeholder='Name'><br>"; echo "<input id='create_name' type='text' placeholder='Name'><br>";
echo "<span class='error-msg create_name'></span><br>";
echo "<button id='create_submit'>Créer</button>"; echo "<button id='create_submit'>Créer</button>";
echo "</form>"; echo "</form>";
@ -96,7 +97,7 @@
echo "<input id='remove_search_id' type='hidden' value=''>"; echo "<input id='remove_search_id' type='hidden' value=''>";
// Indice du resultat // Indice du resultat
echo "<span class='remove_search_view'>machine <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>"; echo "<span class='remove_search_view'>machine <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>";
echo "<button id='remove_search_submit' class='search'>Trouver</button><br>"; echo "<button id='remove_search_submit' class='search'>Trouver/Suivant</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>"; echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
@ -126,11 +127,12 @@
echo "<input id='edit_search_id' type='hidden' value=''>"; echo "<input id='edit_search_id' type='hidden' value=''>";
// Indice du resultat // Indice du resultat
echo "<span class='edit_search_view'>machine <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>"; echo "<span class='edit_search_view'>machine <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>";
echo "<button id='edit_search_submit' class='search'>Trouver</button><br>"; echo "<button id='edit_search_submit' class='search'>Trouver/Suivant</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>"; echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
echo "<input id='edit_name' type='text' placeholder='Name'><br>"; echo "<input id='edit_name' type='text' placeholder='Name'><br>";
echo "<span class='error-msg edit_name'></span><br>";
echo "<button id='edit_submit' disabled>Modifier</button>"; echo "<button id='edit_submit' disabled>Modifier</button>";
echo "</form>"; echo "</form>";

View File

@ -108,7 +108,7 @@
echo "<input id='remove_search_id' type='hidden' value=''>"; echo "<input id='remove_search_id' type='hidden' value=''>";
// Indice du resultat // Indice du resultat
echo "<span class='remove_search_view'>utilisateur <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>"; echo "<span class='remove_search_view'>utilisateur <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>";
echo "<button id='remove_search_submit' class='search'>Trouver</button><br>"; echo "<button id='remove_search_submit' class='search'>Trouver/Suivant</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>"; echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
@ -143,20 +143,20 @@
echo "<input id='edit_search_id' type='hidden' value=''>"; echo "<input id='edit_search_id' type='hidden' value=''>";
// Indice du resultat // Indice du resultat
echo "<span class='edit_search_view'>utilisateur <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>"; echo "<span class='edit_search_view'>utilisateur <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>";
echo "<button id='edit_search_submit' class='search'>Trouver</button><br>"; echo "<button id='edit_search_submit' class='search'>Trouver/Suivant</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>"; echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
echo "<input id='edit_code' type='text' placeholder='CO-DE-RF-ID'><br>"; echo "<input id='edit_code' type='text' placeholder='CO-DE-RF-ID'><br>";
echo "<span class='error-msg edit_code'></span><br>"; echo "<span class='error-msg edit_code'></span><br>";
echo "<input id='edit_username' type='text' placeholder='Username'><br>"; echo "<input id='edit_username' type='text' placeholder='Username'><br>";
echo "<span class='error-msg create_username'></span><br>"; echo "<span class='error-msg edit_username'></span><br>";
echo "<input id='edit_firstname' type='text' placeholder='Firstname'><br>"; echo "<input id='edit_firstname' type='text' placeholder='Firstname'><br>";
echo "<span class='error-msg create_firstname'></span><br>"; echo "<span class='error-msg edit_firstname'></span><br>";
echo "<input id='edit_lastname' type='text' placeholder='Lastname'><br>"; echo "<input id='edit_lastname' type='text' placeholder='Lastname'><br>";
echo "<span class='error-msg create_lastname'></span><br>"; echo "<span class='error-msg edit_lastname'></span><br>";
echo "<input id='edit_mail' type='text' placeholder='Mail'><br>"; echo "<input id='edit_mail' type='text' placeholder='Mail'><br>";
echo "<span class='error-msg create_mail'></span><br>"; echo "<span class='error-msg edit_mail'></span><br>";
echo "<button id='edit_submit' disabled>Modifier</button>"; echo "<button id='edit_submit' disabled>Modifier</button>";
echo "</form>"; echo "</form>";