Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a form with an entity field, without the query_builder work fine, but with the query_builder the form display the result of the query but is not valid when is submited.

//tecnicosType
$builder->add('dt', 'entity', array(
    'class' => 'MSKLigaBundle:Jugadores',
    'label' => 'DT',
    'query_builder' => function(
    \MSK\LigaBundle\Entity\JugadoresRepository $er) use($equipoId){
        return $er->getJugadores($equipoId);
    },
    'property' => 'nombreCompleto',
    'empty_value' => "Sin definir",
    'required' => false
    ))

And the function is

public function getJugadoresQueryBuilder($equipo)
{
    $queryBuilder = $this->createQueryBuilder('j');
    return $queryBuilder->select('j')
        ->where('j.equipo_id = :equipo')
        ->setParameter('equipo', $equipo);
}

when the form is submited return

array
'dt' => 
array
  0 => string 'This value is not valid.'

If i coment the query_builder the form validate fine. I can't find the solution, thank for any help.

share|improve this question
    
Does the MSKLigaBundle:Jugadores entity have some validation markup? (Annotation) Or the form has any validation? Please paste some relevant code. –  Debreczeni András Jun 23 at 17:49
    
no, they don't have any validation. –  Maske Jun 23 at 18:36
    
where does that $equipoId come from? How and where is that declared? –  Debreczeni András Jun 23 at 18:58
    
this is a property of the equiposTecnicosType (this form) And is setted by the function "setEquipo". $equipoId = $this->getEquipo(); –  Maske Jun 23 at 19:11
    
thank you Debreczeni, the problem is $equipoId, this value is passed the first time but no the second. $equipoTecnicos = new equipoTecnicosType(); $equipoTecnicos->setEquipo($equipo->getId()); $formTecnicos = $this->createForm($equipoTecnicos, $tecnicos); –  Maske Jun 23 at 20:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.