Is it possible to rewrite the value using views field rewrite results? Possibly even respect the global field as the value.

I would like to use search autocomplete with entity reference autocomplete field. If we can rewrite the value from "Title" to "Title (nid)" using views, then search autocomplete would provide a simple and efficient method for filtering and selecting from a large list of available entities.

Currently: I can rewrite the autocomplete display. Selecting it inserts the original value into the field without the rewrite. Alternatively, global fields are not even acknowledged.

Grouping, filtering, multiple search values... this module provides everything to make discovering available entity references simple.

CommentFileSizeAuthor
#2 autocompletion.png14.28 KBdom.
#2 view_conf2.png6.55 KBdom.
#2 view_conf.png17.15 KBdom.

Comments

dom.’s picture

Hi !

Rewriting fields in the view should work. I will have a try at it tomorrow and come back with further details.

Dom.

dom.’s picture

Status: Active » Patch (to be ported)
StatusFileSize
new17.15 KB
new6.55 KB
new14.28 KB

Hi !

Here is how to do what you need :

- Create a view using the "Autocomplete JSON style"
- Add two rows : the node title and the node nid
- Rewrite the output of the nid field to "[title] ([nid])" (see screenshot view-conf.png)
- In Autocomplete JSON style settings : choose the output field as value, link and autocompletion field (see screenshot view-conf2.png)
- Now some little code change : in the file : views\theme\views_search_autocomplete_style.theme.inc line 52, find :
$object['value'] = trim($row[$style_options['input_label']]->raw);
change it to :
$object['value'] = trim(strip_tags($row[$style_options['input_label']]->content));
- In your autocomplete form configuration at : admin/config/search/search_autocomplete, disable "auto submit" and "auto redirect" options.

Now when you type the node title in the your input field, it will offer options properly formatted (see screenshot autocompletion.png).

Dom.

jcam88’s picture

Great! Works perfectly. In my opinion, search autocomplete is now one of the best tools for entity referencing.

dom.’s picture

Thanks a lot ! This kind of comment is always very nice to read !

dom.’s picture

Status: Patch (to be ported) » Closed (fixed)

Fix commited.