After any AJAX event in the form (Upload image, add a new field collection row etc.) All Entity Reference fields go blank.

I have multiple entity reference fields, all using a view to get list options.

The issue is occurring on the node edit form.

On first page load, all entity form values are there, and you can edit and save them with no problems. However, If you edit any field that uses AJAX to update, then after ajax has run, all of the entity reference fields lose their options and only show "None" as the single option.

Can anyone think why this would be happening, and what steps I can take to either provide more info, or find a fix?

After using an AJAX field, and then trying to save the form, I get this error in watchdog,

TYPE form
DATE Tuesday, 21 June, 2016 - 08:47
USER squtternutbosh1...
LOCATION http://couplespage.com/node/23/edit
REFERRER http://couplespage.com/node/23/edit
MESSAGE Illegal choice 7 in Venue element.
SEVERITY error

This obviously happens because the select lists are all empty, and illegal choices are detected.

I have posted a screencast of the issue here... http://tinypic.com/r/2pod2dy/9

Comments

Collins405 created an issue. See original summary.

Collins405’s picture

Issue summary: View changes
Collins405’s picture

Upon further investigation...

This is only happening on entity reference fields that are using a view with a contextual filter:nid on them.

On the first load of the edit page, it gets the nid from the "node/55/edit" URL, but after ajax, that contextual filter argument gets lost for some reason, and all options in the select disappear.

I have no idea where to start looking for this, but will investigate further. Any help would be greatly appreciated. This is a pretty serious bug for my site development.

Collins405’s picture

I finally solved this.

There is a patch here... https://www.drupal.org/files/issues/entityreference-use-tokens-2010898-1... That allows you to use tokens in the Entity Reference Fields "Pass argument to view" field.

The problem was that after AJAX, the view I was using for the Entity Reference was losing its contextual filter argument. This patch, and the use of the token fixes the problem nicely.

Collins405’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.