Commit 1dc0cb57 authored by Mat's avatar Mat

crée et insère le formulaire

parent aeea9cb7
<?php
namespace APIBundle\Form\Owner;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TechnoBundle\Form\Owner\OwnerType;
class OwnerAPIType extends OwnerType
{
/**
*
*/
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver->setDefault('csrf_protection', false);
}
}
......@@ -105,8 +105,11 @@ class OwnerController extends MasterController
*/
public function mainDisplayAction()
{
// une seule fonction interroge l'API et retourne tous les élém de la page
return $this->render('@Techno/Ajax/Owner/mainDisplay.html.twig');
$form = $this->createForm(OwnerType::class);
return $this->render('@Techno/Ajax/Owner/mainDisplay.html.twig', array(
'formOwner' => $form->createView()
));
}
......
......@@ -24,11 +24,13 @@ class OwnerType extends AbstractType
$builder->add('firstname', TextType::class, array(
'label' => 'Prénom',
'required' => true,
'label_attr' => array(),
'attr' => array()
));
$builder->add('lastname', TextType::class, array(
'label' => 'Nom',
'required' => true,
'label_attr' => array(),
'attr' => array()
));
......@@ -46,6 +48,7 @@ class OwnerType extends AbstractType
parent::configureOptions($resolver);
$resolver->setDefault('data_class', Owner::class);
$resolver->setDefault('novalidate', true);
}
......
......@@ -13,6 +13,7 @@
</a>
<div class="hidden" style="margin-top: 1em;">
{{ form(formOwner) }}
</div>
{% endblock %}
......@@ -104,6 +105,10 @@
reloadTableOwner();
let form = document.querySelector('form[name="owner"]');
// form[name$="owner"] .. regex, qui finit par owner
// form[name^="owner"] .. regex, qui commence par owner
let createBtns = document.querySelectorAll('.btn-create');
// ou for (let currentBtn of createBtns)
......@@ -111,7 +116,18 @@
// 'e' veut dire 'event'
currentBtn.addEventListener('click', function(e){
form.parentNode.classList.remove('hidden');
});
});
form.addEventListener('submit', function(e) {
// Annule l'événement, mais préserve la fonction callback
e.preventDefault();
console.log('hop');
});
</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