I am using this in Genemu form bundle
add('users', 'genemu_jqueryautocompleter_entity', array(
'route_name' => 'ajax_user',
'class' => Acme'\UserBundle\Entity\OldUser',
'multiple' => true,
'required' => false
))
I am able to multiselect uses and data enters inside ok. But even if i delete whole textbox , my values still remain in database. looks like i am not able to delete it. They enter ok but dont get updated.
If i use normal multiselect without autocomplete , then everything is ok
EDIT:
I mean just like when we ask question in SO and selects tags while typing. then we can remove the tags by deleting text. in my case i can add the users while typing but deleting the characters dont delete the users. in the hidden field , they are still there
Have you tried to put the orphanRemoval=true
on your entity property (users) so it can delete them ?
More on orphalRemoval
http://docs.doctrine-project.org/en/2.0.x/reference/working-with-associations.html#orphan-removal
I believe this is a bug for genemuBundle. What I can see is that if you change the value, the value will get change in the real input (the javascript from GEnemu Bundle makes it hidden), but if you delete the value inside the input, nothing changes, so the old value remains.
When you submit the form, the old value gets submitted, therefore you can't really delete stuff.
The correct way to solve it should be make a better the javascript, setting the value of the real hidden input to blank, genemuBundle should take care of it, but while we wait until they correct that we can do something like:
$("#autocompleter_name_input").change(function(){
if($("#autocompleter_name_input").val()==""){
$("#name_input").val("");
}
});
(I didn't try that though, I am doing this other workaround. Also this is for a single, not for your case which is a multiselect, therefore making this a little bit more complicated...)
As a workaround, you can process the request in your controller:
Genemu sends in the request also what the user literally type in the input. So you should have in your $request->request->all() something similar to that:
Array
(
[your_entity_name] => Array
( all the fields, even with the old values)
[autocompleter_your_entity_name] => Array
( what the user actually input)
)
Just use that to add more validation for the form and do whatever you wish with your entity in your controller.
Sorry for not making it a complete answer and just give workarounds...