Commit 730f14ed authored by Mat's avatar Mat

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 @@
namespace APIBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use APIBundle\Form\Owner\OwnerAPIType;
......
......@@ -19,7 +19,7 @@ class OwnerAPIType extends OwnerType
// ok, on met ça en développement, le temps de régler
// 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));
}
......
......@@ -4,6 +4,7 @@ namespace TechnoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Owner
......@@ -27,6 +28,12 @@ class Owner
* @var string
*
* @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;
......@@ -34,6 +41,12 @@ class Owner
* @var string
*
* @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;
......
......@@ -195,10 +195,7 @@
form.addEventListener('submit', function(e)
{
let form = this;
// Annule l'événement, mais préserve la fonction callback
e.preventDefault();
e.preventDefault(); // Annule l'événement, mais préserve la fonction callback
postAJAX(submitURL, function()
{
if (this.readyState === 4)
......@@ -209,7 +206,13 @@
form.parentNode.classList.add('hidden');
} 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');
}
}
......
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