I trying to make a form for finding users with isActif, actifuser are user's field.
My code:
class CsUsersSearchType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('isActif', ChoiceType::class, [
'label' => 'Actif ?',
'required' => false,
'choices' => [
'Actif' => 1,
'Inactif' => 0,
]
]);
}
}
In Twig:
<button onclick="myFunction()">Reset</button>
with JS:
function myFunction() {
document.getElementById('isActif').value="";}
But when I chose 'Actif' for example and I clicked Reset, myFunction() is not done.
I trying also EntityTyp, same as:
->add('isActif', EntityType::class, [
'class' => CsUsers::class,
'label' => 'Actif ?',
'required' => false,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u')
->select('u.actifuser')
->distinct()
;
}
]);
I received:
Argument 1 passed to Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader::getIdValue() must be an object or null, bool given
Could someone help me out making this, or link me an example ?
CodePudding user response:
I finally fixed this problem by using JQuery. But I don't know why. If anyone know, let me know.