Commit 730f14ed authored by Mat's avatar Mat
Browse files

ajoute une contrainte sur les champs, on déclenche bien une 400

il manquait un use dans le controller
parent 37c0a30b
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace APIBundle\Controller; namespace APIBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use APIBundle\Form\Owner\OwnerAPIType; use APIBundle\Form\Owner\OwnerAPIType;
......
...@@ -19,7 +19,7 @@ class OwnerAPIType extends OwnerType ...@@ -19,7 +19,7 @@ class OwnerAPIType extends OwnerType
// ok, on met ça en développement, le temps de régler // ok, on met ça en développement, le temps de régler
// les validations au niveau des Asserts, des FormType, // les validations au niveau des Asserts, des FormType,
// qd c'est réglé, on vire cette option !!! (false) // qd c'est réglé, on vire cette option !!!
$resolver->setDefault('attr', array('novalidate' => true)); $resolver->setDefault('attr', array('novalidate' => true));
} }
......
...@@ -4,6 +4,7 @@ namespace TechnoBundle\Entity; ...@@ -4,6 +4,7 @@ namespace TechnoBundle\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/** /**
* Owner * Owner
...@@ -27,6 +28,12 @@ class Owner ...@@ -27,6 +28,12 @@ class Owner
* @var string * @var string
* *
* @ORM\Column(name="Lastname", type="string", length=100) * @ORM\Column(name="Lastname", type="string", length=100)
* @Assert\Length(
* min = 3,
* max = 50,
* minMessage = "Your first name must be at least {{ limit }} characters long",
* maxMessage = "Your first name cannot be longer than {{ limit }} characters"
* )
*/ */
private $lastname; private $lastname;
...@@ -34,6 +41,12 @@ class Owner ...@@ -34,6 +41,12 @@ class Owner
* @var string * @var string
* *
* @ORM\Column(name="Firstname", type="string", length=100) * @ORM\Column(name="Firstname", type="string", length=100)
* @Assert\Length(
* min = 3,
* max = 50,
* minMessage = "Your first name must be at least {{ limit }} characters long",
* maxMessage = "Your first name cannot be longer than {{ limit }} characters"
* )
*/ */
private $firstname; private $firstname;
......
...@@ -195,10 +195,7 @@ ...@@ -195,10 +195,7 @@
form.addEventListener('submit', function(e) form.addEventListener('submit', function(e)
{ {
let form = this; let form = this;
e.preventDefault(); // Annule l'événement, mais préserve la fonction callback
// Annule l'événement, mais préserve la fonction callback
e.preventDefault();
postAJAX(submitURL, function() postAJAX(submitURL, function()
{ {
if (this.readyState === 4) if (this.readyState === 4)
...@@ -209,7 +206,13 @@ ...@@ -209,7 +206,13 @@
form.parentNode.classList.add('hidden'); form.parentNode.classList.add('hidden');
} else if (this.status === 400) { } else if (this.status === 400) {
console.log('BAD REQUEST. DISPLAY ERRORS'); console.log('400 Bad Request');
} else if (this.status === 404) {
console.log('404 Not Found');
} else if (this.status === 500) {
console.log('500 Internal Server Error');
} }
} }
......
Supports Markdown
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