We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I use genemu_jqueryautocompleter_entity inside the LexikFormFilterBundle:
genemu_jqueryautocompleter_entity
$builder ->add('branch', 'genemu_jqueryautocompleter_entity', array( 'route_name' => 'ajax_branch', 'property' => 'name', 'class' => 'PlusquamContractBundle:Branch', 'required' => true ));
My AJAX Controller according to the route:
/** * @Route("/branch/ajax", name="ajax_branch") */ public function ajaxAction(Request $request) { $value = $request->get('term'); $em = $this->getDoctrine()->getEntityManager(); $branches = $em->getRepository('AppBundle:Branch') ->findByName($value); // Get branches by user if non-admin $json = array(); foreach ($branches as $branch) { $json[] = array( 'label' => sprintf('%s (%s)', $branch['name'], $branch['company_name']), 'value' => $branch['id'] ); } $response = new Response(); // better way to return json - via header? $response->setContent(json_encode($json)); return $response; }
As suggested in:
A different JSON structure is mentioned here but does not work at all for the autocompleter: http://stackoverflow.com/questions/22143219/want-to-use-genemu-formbundle-autocomplete-with-querybuilder
Generated Javascript:
jQuery(document).ready(function($) { var $field = $('#integrator_contract_filter_branch'); var $autocompleter = $('#autocompleter_integrator_contract_filter_branch'); var $configs = { focus: function(event, ui) { return false; }, select: function(event, ui) { this.value = ui.item.label; terms = ui.item; $field.val(JSON.stringify(terms)); return false; } }; $configs.source = function(request, response) { $.getJSON('/branch/ajax', { term: request.term }, response); }; $autocompleter.autocomplete($configs); });
When I select an entity my hidden input gets populated with the JSON array:
<label for="integrator_contract_filter_branch" class="required">Branch</label><input value="{"label":"Foo (Bar)","value":2}" id="integrator_contract_filter_branch" name="integrator_contract_filter[branch]" required="required" type="hidden"><span class="ui-helper-hidden-accessible" aria-live="polite" role="status">2</span><input autocomplete="off" class="ui-autocomplete-input" id="autocompleter_integrator_contract_filter_branch" name="autocompleter_integrator_contract_filter[branch]" required="required" type="text">
Shouldn't the javasript function populate the hidden input with the ID by default?
Possibly related:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I use
genemu_jqueryautocompleter_entity
inside the LexikFormFilterBundle:My AJAX Controller according to the route:
As suggested in:
A different JSON structure is mentioned here but does not work at all for the autocompleter:
http://stackoverflow.com/questions/22143219/want-to-use-genemu-formbundle-autocomplete-with-querybuilder
Generated Javascript:
When I select an entity my hidden input gets populated with the JSON array:
Shouldn't the javasript function populate the hidden input with the ID by default?
Possibly related:
The text was updated successfully, but these errors were encountered: