genemu/GenemuFormBundle

JQuery Autocompleter in edit mode with ajax

Opened this issue · 3 comments

Hi,

I 've a problem to restore my db value in the autocomplete field :

My form look like

<?php
// ....

->add('field_id', 'genemu_jqueryautocompleter_choice', array(
                'route_name' => 'my_route',
))

And when i submit and show my form the field is well setted and in AutocompleterType::buildView() the $datas contain a label and a value so the autocompleter_value work

But when i passe an object already setted in ViewData i've only a string with the value of my field_id.

I've looked in AjaxSimpleChoiceList and it seems to work that he need values for ajaxChoices and the $this->addAjaxChoices($choice);is only called in the case of a reverse transform in ChoiceToJsonTransformer so not in this case (we use only transform because there is no request to handle)

I think we need to add something like that :

<?php

public function transform($choices)
{

///
if ($this->ajax) {
        foreach ($choices as $choice) {
            $choice = array('label' => // A given option closure to get the label ? //, 'value' => $choice);
            $this->addAjaxChoices($choice);
        }
}

Note: I'm in sf 2.3-dev

hi, looks like a duplicate of #175?

Oups, yest it is ! Have you an idea on when a solution will be merged ?

I'll try to implement this when refactoring the autocompleter, after this feature will be in symfony (symfony/symfony#6602), so for symfony >=2.4 I guess.