Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
technobel.sf
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mathieu
technobel.sf
Commits
25881e70
Commit
25881e70
authored
May 19, 2018
by
Mat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajax, fonction d'affichage des erreurs 400
parent
730f14ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
9 deletions
+27
-9
src/TechnoBundle/Entity/Owner.php
src/TechnoBundle/Entity/Owner.php
+2
-0
src/TechnoBundle/Resources/views/Ajax/Owner/mainDisplay.html.twig
...noBundle/Resources/views/Ajax/Owner/mainDisplay.html.twig
+4
-7
web/js/script.js
web/js/script.js
+21
-2
No files found.
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