Skip to content

Filter doesn´t found  #175

Description

@detectivejd

Hi, how are you? I hope it´s ok. I need your help, the select2entity-bundle css and js work well, but the filter doesn´t else the load all the elements.

I put the code:

PaisRepository:
public function findByFilter($dato){
$em = $this->getEntityManager();
$query = $em->createQuery("select p from App\Entity\Pais p where p.nombre like :nombre")
->setParameter('nombre', '%'.$dato.'%');
return $query->getResult();
}

PaisController:
/**
* @route("/search", name="pais_search", methods={"GET"})
*/
public function search(Request $request){
$items = [];
$em = $this->getDoctrine()->getManager();
$criterio = $request->request->get('q');
$paises = $em->getRepository(Pais::class)->findByFilter($criterio);
foreach($paises as $pais){
$items[] = [
'id' => $pais->getId(),
'text' => $pais->getNombre()
];
}
return new JsonResponse($items);
}

DepartamentoType:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nombre',TextType::class,[
"label" => "Nombre (): ",
"required" => "true",
"empty_data" => '',
"attr" => [
"class" =>"form-control"
]
])
->add('pais', Select2EntityType::class,[
"label" => "País (
): ",
"remote_route" => 'pais_search',
"class" => Pais::class,
"allow_clear" => true,
"placeholder" => "Seleccione País"
])
;
}

I took this picture:

Captura de pantalla de 2021-02-16 23-57-38

I don´t know as resolve the problem and i need your help.
Greetings and thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions