Commit 25881e70 authored by Mat's avatar Mat

Ajax, fonction d'affichage des erreurs 400

parent 730f14ed
...@@ -28,6 +28,7 @@ class Owner ...@@ -28,6 +28,7 @@ class Owner
* @var string * @var string
* *
* @ORM\Column(name="Lastname", type="string", length=100) * @ORM\Column(name="Lastname", type="string", length=100)
* @Assert\NotBlank()
* @Assert\Length( * @Assert\Length(
* min = 3, * min = 3,
* max = 50, * max = 50,
...@@ -41,6 +42,7 @@ class Owner ...@@ -41,6 +42,7 @@ class Owner
* @var string * @var string
* *
* @ORM\Column(name="Firstname", type="string", length=100) * @ORM\Column(name="Firstname", type="string", length=100)
* @Assert\NotBlank()
* @Assert\Length( * @Assert\Length(
* min = 3, * min = 3,
* max = 50, * max = 50,
......
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
form.parentNode.classList.remove('hidden'); form.parentNode.classList.remove('hidden');
} }
else if (this.status === 400) { else if (this.status === 400) {
console.log('BAD REQUEST. DISPLAY ERRORS'); console.log(this.status + ' ' + this.statusText);
} }
} }
}); });
...@@ -151,7 +151,7 @@ ...@@ -151,7 +151,7 @@
reloadTableOwner(); reloadTableOwner();
} }
else if (this.status === 400) { else if (this.status === 400) {
console.log('BAD REQUEST. DISPLAY ERRORS'); console.log(this.status + ' ' + this.statusText);
} }
} }
}); });
...@@ -206,13 +206,10 @@ ...@@ -206,13 +206,10 @@
form.parentNode.classList.add('hidden'); form.parentNode.classList.add('hidden');
} else if (this.status === 400) { } else if (this.status === 400) {
console.log('400 Bad Request'); handleErrors(this);
} else if (this.status === 404) {
console.log('404 Not Found');
} else if (this.status === 500) { } else if (this.status === 500) {
console.log('500 Internal Server Error'); console.log(this.status + ' ' + this.statusText);
} }
} }
......
...@@ -32,7 +32,26 @@ function deleteAJAX(url, callback) ...@@ -32,7 +32,26 @@ function deleteAJAX(url, callback)
xhr.send(null); xhr.send(null);
} }
function handleErrors() function handleErrors(response)
{ {
// 30 lignes pour gérer les erreurs du formulaire POST renvoyé par l'API let message = response.status + '\n' + response.statusText + '\n\n';
let JSONObject = JSON.parse(response.responseText);
let fields = form.querySelectorAll('input[id^="owner"]');
for (let key in JSONObject)
{
for (let field of fields)
{
let fieldName = field.getAttribute('id').replace('owner_', '');
if (JSONObject[key].hasOwnProperty(fieldName)) {
for (let error of JSONObject[key][fieldName].errors) {
message += '* ' + error + '\n';
}
}
}
}
alert(message);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment