Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mathieu
technobel.sf
Commits
25881e70
Commit
25881e70
authored
May 19, 2018
by
Mat
Browse files
Ajax, fonction d'affichage des erreurs 400
parent
730f14ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/TechnoBundle/Entity/Owner.php
View file @
25881e70
...
...
@@ -28,6 +28,7 @@ class Owner
* @var string
*
* @ORM\Column(name="Lastname", type="string", length=100)
* @Assert\NotBlank()
* @Assert\Length(
* min = 3,
* max = 50,
...
...
@@ -41,6 +42,7 @@ class Owner
* @var string
*
* @ORM\Column(name="Firstname", type="string", length=100)
* @Assert\NotBlank()
* @Assert\Length(
* min = 3,
* max = 50,
...
...
src/TechnoBundle/Resources/views/Ajax/Owner/mainDisplay.html.twig
View file @
25881e70
...
...
@@ -125,7 +125,7 @@
form
.
parentNode
.
classList
.
remove
(
'
hidden
'
);
}
else
if
(
this
.
status
===
400
)
{
console
.
log
(
'
BAD REQUEST. DISPLAY ERRORS
'
);
console
.
log
(
this
.
status
+
'
'
+
this
.
statusText
);
}
}
});
...
...
@@ -151,7 +151,7 @@
reloadTableOwner
();
}
else
if
(
this
.
status
===
400
)
{
console
.
log
(
'
BAD REQUEST. DISPLAY ERRORS
'
);
console
.
log
(
this
.
status
+
'
'
+
this
.
statusText
);
}
}
});
...
...
@@ -206,13 +206,10 @@
form
.
parentNode
.
classList
.
add
(
'
hidden
'
);
}
else
if
(
this
.
status
===
400
)
{
console
.
log
(
'
400 Bad Request
'
);
}
else
if
(
this
.
status
===
404
)
{
console
.
log
(
'
404 Not Found
'
);
handleErrors
(
this
);
}
else
if
(
this
.
status
===
500
)
{
console
.
log
(
'
500 Internal Server Error
'
);
console
.
log
(
this
.
status
+
'
'
+
this
.
statusText
);
}
}
...
...
web/js/script.js
View file @
25881e70
...
...
@@ -32,7 +32,26 @@ function deleteAJAX(url, callback)
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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment