Reputation: 59
I implemented the Tinymce's plugin, and it works! In fact, all the text areas now have a text editor. This is my view.
The problem is that this is obviously a form, and when I submit it, doesn't submit at all.
What could be the problem?
Upvotes: 1
Views: 379
Reputation: 59
<?php
// src/AppBundle/Form/RecipeType.php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class RecipeType extends AbstractType
{
protected $currentField;
protected $entity;
public function __construct($entity)
{
$this->entity = $entity;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('titolo');
$builder->add('autore');
$builder->add('tipologia', 'entity', array(
'class' => 'AppBundle:Tipologia',
'label' => 'Tipologia',
'choice_label' => 'name',
));
$builder->add('difficolta','choice',array(
'choices' => array ('1','2','3','4','5')
));
$builder->add('persone','choice',array(
'choices' => array ('1','2','3','4','5','6','6+')
));
$builder->add('tempo');
$builder->add('ingredienti','textarea',array(
'required' => false,
));
$builder->add('procedimento', 'textarea',array(
'required' => false,
));
$builder->add('image', 'file', array(
'data_class' => null,
'required' => false
)
);
$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
$this->currentField = $this->entity->getImage();
});
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$form = $event->getForm();
$inputFile = $form->getData();
$newImage = $inputFile->getImage();
if (is_null($newImage) && !is_null($this->currentField))
{
$inputFile->setImage($this->currentField);
}
});
}
public function getName()
{
return 'recipe';
}
}
THE SOLUTION: In every Textarea field add required false.
$builder->add('ingredienti','textarea',array(
'required' => false,
));
$builder->add('procedimento', 'textarea',array(
'required' => false,
));
Upvotes: 1