Hi,

When editing a node which has an Entity Reference field displayed as a Select list.
http://i.imgur.com/gxIjLFu.png

the node can be created and saved ok *except* if you add an image (via Media Browser, which triggers an Ajax event).
After adding an image (and AJax event is fired), clicking Publish will show a validation error, "An illegal choice has been detected. Please contact the site administrator."
http://i.imgur.com/ghbTgIh.png

Also the select list will now be only populated with the value selected e.g.
http://i.imgur.com/q7QIZnR.png

I have seen a number of similar issues on drupal forums but none of the fixes seemed to work in my case.

Also note that if I change the widget from Select list to Autocomplete the problem goes away.

I don't believe this is a duplicate of any "Illegal choice" bugs listed already as my situation doesn't involve Views or Multi-select fields.
Entity Reference with Views source - https://www.drupal.org/node/2242773
Entity Reference with multi-select field - https://www.drupal.org/node/1045208

Any ideas?

Cheers,
Scott.

Comments

nicolas bouteille’s picture

Hi how did you solve this? I've got the exact same problem with the image field...

nicolas bouteille’s picture

I think you omitted to say that the entity reference field is populated dynamically isn't that your case as well?

teeyo’s picture

I know it's 2 years ago, I don't know if new Drupal versions included the fix, but since this is the first result when we look up the issue, I'll link to the patch that fixes this issue : Patch

Maybe this will help someone .. who knows!

gateway69’s picture

I just came across this and the last answer was a suggested patch from 2 years ago..

I have the same issue as the original post.. when dealing with entity reference and an image field in a content type, if you remove the image and add a new one you get the error "An illegal choice has been detected. Please contact the site administrator." and on top of that my entity ref field gets removed.

Any thoughts on this?

V 7.x.1-5
Drupal 7.56

gateway69’s picture

Priority: Normal » Major

Any time you have an image field and are using a Entity Reference field from a view or anything else the moment you edit this node to change the image, all your entity references that you had either checked or selected are removed and Illegal choice is shown above the image.

So lets say you had a header image, a multi select that is pulling some data from a view.

You first create the node, upload the image select the items in the multi-select and save. This works.

Now your asked to change the image, you remove the image, and it pops up an error with Illegal choice contact admin, and all the think you had selected for multi select are deselected. So you have to upload the image w/o being able to check anything and edit the form again and select the items you needed.

This also is an issue with checkboxes..

I have no idea even where to start to debug this..

PeterStubRaindrop’s picture

I'm having the same problems. Add/remove image/file - and then make a change to a entity reference field and hit save = "An illegal choice has been detected. Please contact the site administrator".

But I also see a problem if validate is not TRUE - then the entity list items disappear.

So its like after a submit/validate - some values get lost?

Anybody?