0

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
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.

http://tinypic.com/r/2pod2dy/9

Update: On further inspection, using dsm($form) to print krumo and check the results, after ajax, it takes over a minute to complete the page, but all of the values are still there in the array, just not in the actual select list. They are also still there in the page source. Something is making them not show. I will look into someway to rebuild the form after ajax, but Im grabbing at straws here. Any help really appreciated.

Update 2: On even further inspection. Values are only lost when it is a view Entity Reference display that is being used to populate the values. When reverting to a simple filter by bundle list, they show after ajax. Something is causing the view to lose its results after ajax.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.