Commit 623a4625 authored by Mat's avatar Mat

la requête POST de AJAX + diverses choses qui manquaient ->

* des use dans le contoller de l'API
* handlerequest prend un $request !!
* un affichage plus détaillé du formulaire
* on vide le tbody avant de le reloader !
parent 6d55435a
......@@ -2,7 +2,11 @@
namespace APIBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use APIBundle\Form\Owner\OwnerAPIType;
use TechnoBundle\Entity\Owner;
class OwnerController extends MasterAPIController
{
......@@ -61,7 +65,7 @@ class OwnerController extends MasterAPIController
$owner = new Owner();
$form = $this->createForm(OwnerAPIType::class, $owner);
$form->handleRequest($owner);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
......
......@@ -17,7 +17,10 @@
</a>
<div class="hidden" style="margin-top: 1em;">
{{ form(formOwner) }}
{{ form_start(formOwner) }}
{{ form_errors(formOwner) }}
{{ form_rest(formOwner) }}
{{ form_end(formOwner) }}
</div>
{% endblock %}
......@@ -63,6 +66,8 @@
// La fonction AJAX
function reloadTableOwner()
{
tbody.innerHTML = null;
getAJAX(ownersURL, function()
{
if (this.readyState === 4
......@@ -131,12 +136,22 @@
form.addEventListener('submit', function(e) {
let form = this;
// Annule l'événement, mais préserve la fonction callback
e.preventDefault();
console.log('hop');
let xhr = new XMLHttpRequest();
xhr.onreadystatehange = function() {
if (this.readyState === 4 && this.status === 200) {
reloadTableOwner();
}
};
xhr.open('POST', '{{ path('api_owner_create') }}', true);
xhr.send(new FormData(form));
});
</script>
{% endblock %}
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