When using a view for displaying entities in a references search dialog the wrong entity will be selected when clicking results on the second or higher page. References dialog will select an entity but only one from the first views page.

This is caused by the Drupal.settings.ReferencesDialog.entities javascript settings array not being updated when selecting another page in the view. It keeps using the entities returned on the first page.

This can be fixed by moving the javascript settings generation logic from the references dialog display plugin's execute method to its render method. Execute is never called on view preview, which is the method views uses to output ajax views.

Patch with a fix follows.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

klaasvw’s picture

This patch moves the javascript settings logic to render.

I'm not sure why views doesn't use the execute method on preview so it might be worth looking deeper into this. For now this fix works fine though.

klaasvw’s picture

Status: Active » Needs review

Setting status...

klaasvw’s picture

Here's a reroll against HEAD that fixes whitespace issues.

FiNeX’s picture

The patch works fine, moreover it make works views with AJAX enabled :-)

Great!

clashar’s picture

I successfully applied patch from #3, but search still shoes nothing.
Tried clear caches, run update.
"Reference dialog Search" display shows correctly data in views, but not on search within node as supposed.

any idea?

FiNeX’s picture

Did you added multiple "Reference Dialog Search" display on the same views?

clashar’s picture

firstly accidentally I added 2 displays, but then deleted second one.
Is it due to this?

FiNeX’s picture

I've had the same problem, after I've recreated the views from scratch, one display each, and now all works fine.

clashar’s picture

FiNeX, thank you for hint, I've got many settings and displays in views, but will try to create a new view only with reference dialog display

clashar’s picture

so I created a new view, but then 2 two different errors appear:
1) when field in view is not as link ("Link this field to the original piece of content" is not checked) and I click search in this new search window I got error:

Notice: Undefined property: stdClass::$nid in references_dialog_plugin_display->render() (line 212 of Z:\home\paris11.kz\www\emploi\sites\all\modules\references_dialog\views\references_dialog_plugin_display.inc).
...
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of Z:\home\paris11.kz\www\emploi\includes\entity.inc).

2) when field in view is a link, I could search - there is a list of results, and if I choose the cell, it's ok, but if I click on field as link in opened search (ref dialog) window then i got:

The requested page "/emploi/job/1/cv/348&render=references-dialog&closeonsubmit=0" could not be found

FiNeX’s picture

@clashar: you should open a separate bug report for those errors

FiNeX’s picture

I've just tested the patch #3 on the latest -dev version and it works fine :-)

P.S @clashar: The issue about multiple display should have been fixed: http://drupal.org/node/1433346

clashar’s picture

FiNeX,
thank you I will create a new issue.

fabsor’s picture

Status: Needs review » Fixed

This seems to work fine and people have signed off on it, so I will take the liberty of commiting this. Thanks!

Status: Fixed » Closed (fixed)

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