I use the entityreference view widget embedded in a node creation form. Once the node has been created, when I edit the node, the widget works as expected: selected items are shown on the left side of the widget, not-selected items on the right side; clicking on the checkbox makes the entity change sides (either from right to left or the other way round).

But when creating a new node, the widget does not work as expected: When I click on an entity's checkbox, the entity does not move from the right side to the left side, still showing "No items have been selected." on the left side.

Comments

chrdr’s picture

BTW, when saving the new node there is an error message "An illegal choice has been detected. Please contact the site administrator." for each entity that has been selected, and a warning: "Warning: uasort() [function.uasort]: The argument should be an array in entityreference_view_widget_validate() (line 477 of /www/drupal/sites/all/modules/entityreference_view_widget/entityreference_view_widget.module)."

I don't know if this helps you to find the bug.

bojanz’s picture

chrdr’s picture

I have applied the patch, but I'm sorry, it does not solve the issue.

bojanz’s picture

Okay, thanks for trying. Will give the module attention on the weekend if Damien doesn't beat me to it.

sea4’s picture

any luck with this issue?... i am getting the save behavior. when i try to create a new node, it throws the same error.

thanks & great module :-)

sea4’s picture

ok i just discovered, when i don't select anything and save... ie, the field isn't required, it throws the error.

When there are no items in the view, it throws the errors below on save:

Warning: uasort() [function.uasort]: The argument should be an array in entityreference_view_widget_validate() (line 477 of /home/site/public_html/sites/all/modules/entityreference_view_widget/entityreference_view_widget.module).
Notice: Undefined index: add in entityreference_view_widget_validate() (line 489 of /home/site/public_html/sites/all/modules/entityreference_view_widget/entityreference_view_widget.module).
Warning: array_filter() [function.array-filter]: The first argument should be an array in entityreference_view_widget_validate() (line 489 of /home/site/public_html/sites/all/modules/entityreference_view_widget/entityreference_view_widget.module).
Warning: Invalid argument supplied for foreach() in entityreference_view_widget_validate() (line 490 of /home/site/public_html/sites/all/modules/entityreference_view_widget/entityreference_view_widget.module).

It works fine, once there are there are results in the view and you select one or more of the results from that view.

sea4’s picture

Has anyone had any luck? So far the errors are thrown either when none of the entities are selected on a new node or when there is no items in the the view on save.

i am guessing there is no validation for none or 0 somewhere... hope this helps a little bit.

chrdr’s picture

Strange: The issue I described in the title ("Selected items not being added to the list of selected items.") seems to be solved although there has not been a new release since then. Seems that another module (Views?) caused the problem.

But I still get "Warning: uasort() [function.uasort]: The argument should be an array in entityreference_view_widget_validate() (line 477 of .../sites/all/modules/entityreference_view_widget/entityreference_view_widget.module)." when saving a new node. And I also get the message if I add an item to the list of selected items (which works now) and then (instead of saving) click on any link on the page that fetches another page of my site. So the warning is not caused by saving the node, but by selecting one or several items in the entity reference view widget.

Since the bug described in the title does not exist any more and we are meanwhile discussion a different issue:
Should I open a new issue for that (and mark this one fixed), or should I change the title of this issue?

das-peter’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB

I'd say the uasort() should only be executed if there's really something to sort.
Attached patch moves the command into the already existing condition.

bojanz’s picture

Title: Selected items not being added to the list of selected items. » Don't call uasort() if there's nothing to sort
Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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