0
votes

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        collins
MESSAGE     Illegal choice 7 in Venue element. 
SEVERITY    error

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

heres a screencast of the issue. http://tinypic.com/r/2pod2dy/9

Is there a way to use form API to rebuild the form and entity reference options after an ajax action?

1

1 Answers

0
votes

I finally solved this.

There is a patch here... https://www.drupal.org/files/issues/entityreference-use-tokens-2010898-126.patch 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.