I have a content type with with 3 fields in addition to others, but these 3 are the subject of my issue. All fields are entity references and all fields use the Select list widget. The first two fields use "Filter by entity reference view" for Entity Selection, but the last one uses the "Simple" option. I'm not sure order matters here, but it helps to distinguish the fields. The second "Filter by entity reference view" field triggers an ajax call to update the third "Simple" field. This is the same setup as the Ajax Dependent Dropdown example in the Examples module. The ajax works fine and does what it should. However when I submit the form, I receive the "An illegal choice has been detected..." error for the first entity reference (the one not involve in the ajax transaction) and the values for that selection disappear IF I made a selection change of the second ("master") dropdown. If I don't alter that second dropdown, no problem. Any idea why this process would affect the first entity reference selection which is not involved in the ajax call?


sprocketman’s picture

Category: support » bug

I'm promoting this to a bug report. It seems that during the ajax call, the field #options get reset, but the options never get repopulated, thus the result of an illegal option chosen when validating the form. Any help would be greatly appreciated.

sprocketman’s picture

Status: Active » Closed (works as designed)

I finally realized what was going on. I had been using a contextual filter for the reference view which relied on using $_GET['destination'], which only worked on the initial load of the node form. The destination was a particular node from which I was extracting the node id, but once ajax was called that same destination was not available. I'm closing this due to my own error.

operations’s picture

I have almost the same issue. Can you please let me know how did you solve it?

nyl_auster’s picture

I had somehow a similar issue : when uploading an image, one of my entity reference field above was complaining about an illegal choice.
This entityreference field was filtered by a "entityrefence view", relying on "content id from url" in contextual filters. (nid of node, on the node edit form)

I suppose than when upload a new image, an ajax call is made and form is rebuilt from ajax url, which does not contain my nid.

Workaround i found : use php in contextual filter and return ALL values when argument is not found, so that "illegal choice" is never fired.

something like

return (arg(0) == 'node' && is_numeric(arg(1)) ? arg(1) : 'all';

skywalk’s picture

Just had my aha! moment. Thanks so much nyl auster! I had the exact same problem. Sure enough removing the contextual filter fixed the issue.

jenniferannwalsh’s picture

Issue summary: View changes

Thanks also to nyl auster. This helped me figure out how to fix a similar issue with the 'illegal choice' error. Instead of using PHP, I checked the 'Specify validation criteria' box and selected 'Display all results for the specified field' in the' Action to take if filter does not validate'.

JvE’s picture