0

How to implement choose user type in Symfony2 Forms?

I want to create in form filed called user. And be able to choose user from DB (via Doctrine) with autocomplete.

2 Answers 2

1

1)You have to add in your form builder :

  • a field text widget, unmapped (will contain the text of the user type)
  • a hidden field, unmapped (will contain the id of the use type)

2)Use the javascript library you want (i.e bootstrap typeahead is a good one).

3)Then, the javascript trigger an ajax method pointing on a action on your controller. This action return a list of user type (most likely encoded in json format)

4) Once the form is submited, in the update/create action of yours, find the entity corresponding to the hidden id submited, and link it to the entity

Sign up to request clarification or add additional context in comments.

Comments

0

It seems that you are looking for integration select2. check this out

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.