If you need to have the entityreference field required (for times when you also have submissions without a prepopulated url) the submission fails with a form_set_error on the field as if it were empty (though it was prepopulated correctly).

I can't figure out how to fix it yet to submit a patch, but I at least wanted to get it reported.

Comments

jyee’s picture

I'm experiencing something similar, however it seems to depend on other fields in the form.

For example, I have a multiple value file field in my form. When a user submits the form with one file, the form submits correctly. When a user submits with two files, the form returns a "field X is required" error.

ezheidtmann’s picture

I am also experiencing problems of a similar nature, in an interaction with og_role_field. I'll update here when I find out what's going on.

ezheidtmann’s picture

In my situation, the problem is that og_role_field needs to access the $items array for the og_group_ref field in the validation step, but entityreference_prepopulate doesn't get involved until after validation, when insertion is about to happen.

Working on a fix.

ezheidtmann’s picture

I resolved my issue by calling entityreference_prepopulate_get_values_from_url() in og_role_field_field_validate(). It's super ugly, but right now I don't have the time or patience to wade through the field & form APIs to find the proper fix.

The proper fix would probably involve adding a #process callback for entityreference_prepopulate when it is enabled, or a validation callback.

gthing’s picture

Priority: Normal » Critical

I'd call this critical since it creates a situation where the entity reference field doesn't work.

Any progress on a fix or workaround?

ezheidtmann’s picture

Hey gthing, if you're experiencing this problem, could you provide more information on your situation? What values are you prepopulating in your entityreference field? What other modules are in use?

ezheidtmann’s picture

jyee: Is your issue possibly related to this one? #1502972: Issues with ajax file upload fields

gthing’s picture

ezheidtmann: Thanks for your response. Your link to jyee was exactly the problem I'm having. I'll update to the latest version.

howards’s picture

Issue summary: View changes

I was having the same issue and ran across #1958800: AJAX causes entityreference_prepopulate_get_values_from_url to fail and it appears to fix the issues. Try that!