I created two content types:
Step1:create a content type "player" and add cck fields player_number and player_name, the node-title is build by modules autonodetitle and token, so it's the same as player_name, create some players
Step2: create a content type "tournament" and add one or more node reference field/s to content type player,
The select list is sorted alphabetically by node-title of content type "player", so by player_name
I'd like to sort the list by player_number, so I created a new view (views2-module) with fields player_number and player_name and sort-criteria player_number ASC. I referenced the nodereference-field "participant" to this view.
Now, the select list shows the following sorted fields: player_number, player_name and "title":title (the player_name)
So the player_name is doubled.
How can I hide the title of the referenced node in the select list ?
I think, it's not a big problem, because only the node_nid is stored in database.

CommentFileSizeAuthor
#5 sreenshot.jpg81.95 KBMicha1111
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

likewhoa’s picture

just ran into this and would like an answer as well, It seems the node reference's view feature is the issue here but one needs to select a view and only show what that view is querying not the extra "title foobar" bit.

likewhoa’s picture

Assigned: Micha1111 » Unassigned
likewhoa’s picture

Version: 6.x-2.0-rc6 » 6.x-2.x-dev
Category: feature » bug
drewish’s picture

Category: bug » support
Status: Active » Fixed

you just need to setup the view correctly. if you're seeing "title" you need to remove the label from the field name. if you're seeing double values you need to remove the duplicate fields.

Micha1111’s picture

Status: Fixed » Active
FileSize
81.95 KB

I think, this solution is not a fix, because the view has only two fields (player_number and player_name with labels) without node-title of nodes from nodetype players (sreenshot2)

But the node-title is shown in cck-form-selectfield. (sreenshot1)

After deletion of the label of field player_number and delition of the field player_name (sreenshot3), the player_number and the node_title (with label "Titel:" are shown in cck-form-selectfield (sreenshot4).

So the node-title is always shown, but it isn't set in views-settings !!

drewish’s picture

Category: support » task

ah, you're right. talked to yched on irc and the solution is to exposed a views display and let you create your own fields.

yched’s picture

Category: task » feature
Status: Active » Closed (works as designed)

Actually, this is not related to whether the custom view display we use is exposed or not. The fact is that we explicitly force the node title (or user name, in the case of userrefernce fields) to be present as a field in the view.
_nodereference_potential_references_views() :

    // We do need title field, so add it if not present (unlikely, but...)
    $fields = $view->get_items('field', $display);
    if (!isset($fields['title'])) {
      $view->add_item($display, 'field', 'node', 'title');
    }

This is because the 'autocomplete' widget needs the node title to fill in "node_title [nid:node_id]" in the textfield when the user picks an autocomplete suggestion. Granted, the other widgets (select, radios/checkboxes) don't need it, but the code workflow is pretty tight and it's hard to do special cases. I don't really see a workaround here.

drewish’s picture

yched, well that pretty much defeats most of the value of using views for the lists... are you sure we couldn't come up with some kind of a work around?

yched’s picture

Status: Closed (works as designed) » Active

That sounds a little dramatic - it's been like that since 4.7, and I think the feature found a few use cases since then, even with that limitation ;-)

Well, thinking about it a little more, there should be a way to have a db field (node title) retrieved in the views results but not being part of the actual views 'fields' . If this can be done (and if we have a consistent way to get it from the results, whether 'node: title' field is actually present in the view or not), then we could alleviate that constraint.

Then, of course, comes the usual issue of changing the behavior of existing setups : after upgrading to cck 2.2, the titles disappear from my noderef widgets if my view didn't have the title field so far.

KarenS’s picture

The Views UI has a checkbox for field options that are needed in the query but not to be displayed. Maybe there is some way to use that to include the field but not display it. I haven't looked into the Views code to see where that comes in to play or exactly what it would change in these results.

yched’s picture

True, I forgot that option. This might be a solution - if the 'title' field is not present, we force it in as 'not displayed'.
Patch anyone ? :-)

drewish’s picture

yched, i think the option you're thinking of is "exclude from display"... but if the ajax needs the title to match nids then that seems like the bigger stumbling block...

Micha1111’s picture

Perhaps, it's easier to hide only the label of the node-title ?

I mean: "Title:"

That's ok for me, because I build the node-title with modules token and autonodetitle from field player_name, so node-title and field player_name are always identical.

kenorb’s picture

Status: Active » Needs work

Marked #350174: get rid of Title from autocomplete referenced field when using Views as duplicated.

Title is added in _nodereference_potential_references_views():

    // We do need title field, so add it if not present (unlikely, but...)
    $fields = $view->get_items('field', $display);
    if (!isset($fields['title'])) {
      $view->add_item($display, 'field', 'node', 'title');
    }

I've commented out this line:

$view->add_item($display, 'field', 'node', 'title');

Then it's throwing the error:

Fatal error: Cannot access empty property in cck\includes\views\handlers\content_plugin_style_php_array_ac.inc on line 24

That's:

    foreach ($sets as $title => $records) {
      foreach ($records as $label => $row) {
        $results[$row->{$base_field}] = array(
          'title' => $row->{$title_field_alias},
          'rendered' => $this->row_plugin->render($row),
        );
      }
    }

So I've changed this code to:

    foreach ($sets as $title => $records) {
      foreach ($records as $label => $row) {
        if (isset($row->{$title_field_alias})) {
          $results[$row->{$base_field}]['title'] = $row->{$title_field_alias};
        }
        $results[$row->{$base_field}]['rendered'] = $this->row_plugin->render($row);
      }
    }

And it's seems to work fine.

I don't care for now that there is no title in the field (#7). It should be replaced with some field as well.
I think without Title in autocomplete list is looks better than without Title in the field.
In some cases some people don't use title at all, because auto_nodetitle doesn't generate titles from the fields during creation, so for most of the cases Title contain rubbish.

Probably most of the people who wanted to hide the Title now will be interested with searching string in CCK fields as well via autocomplete:
Here is related case: #375690: Nodereference autocomplete doesn't match all of view's fields

CobraMP’s picture

thank you kenorb. so I'm curious if the dev version, or next drop of cck will include something to be able to drop the title via the UI?

jlevy’s picture

I've been able to work around this issue:

1) add the title field to your view
2) check the 'exclude from display' box for that field

That should do it until the bug is fixed.

Jeff

likewhoa’s picture

I don't see this being an issue with latest -dev for me anymore.

kenorb’s picture

I'm not sure if you talking on the same thing, but I don't see much changes and title is still hardcoded.

kenorb’s picture

Status: Needs work » Fixed

But I think #16 is a good solution.
I've tested and it's working.
The only issue is to replace the title of field somehow after selected some record.
If somebody will have better solution, please re-open it.

yched’s picture

Changing the code to force-add the 'title' field as 'excluded' if it is not present in the original view seems an easy change.
My main worry is that it will break existing sites that might implicitly rely on the fact that the title was added no matter what.

kenorb’s picture

yched: it can be solve in similar way to this one:
http://drupal.org/node/375690#comment-1263293
Most of the views used as argument have no fields defined because are not supported, so if there are some fields defined, we can replace them instead of default title. I think it will not break existing websites.

yched’s picture

I fail to see how this is a fix.
Sample break case :
I created a view with filters and sorts to define the nodes that are refererencable in my field_noderef field. I didn't even have to bother about adding actual fields to the view, it works out of the box (displaying titles). Then I install the new version of CCK that behaves as decribed in #20. Nothing displays in my select box or in the autocompletion results anymore => I have to manually edit the view and add the title.

I don't think there's a workaround.

Status: Fixed » Closed (fixed)

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

javi-er’s picture

#16 worked perfect for me.

likewhoa’s picture

Status: Closed (fixed) » Active

#16 is not a workaround re-opening since cck fields are still being appended with '- Title: Name' after content.

timtrinidad’s picture

I know this issue is pretty old, but I used the following workaround: include the "Node: Title" in the fields, remove the label (i.e. make it blank), check the "rewrite the output of this field", and enter a "[space]" (i.e. a blank character). This works pretty well except for the " - " at the end of the select option when displayed.

TomSherlock’s picture

I don't under comment #25. i have successfully applied the work-around in #16.

I'm using a nodereference with a select list. By applying #16, I no longer see 'title: name' after the field values.

cpall’s picture

I second this, it works fine.

Grayside’s picture

#16 works for me as well.

I suspect that while the title is hardcoded, it does not unset any existing array configuring how to handle the Title field options (for a first use of the Title as a views field). As such, if you mark it as excluded or rewritten (or really any of the options not specifically configured in _nodereference_potential_references_views), they will carry over into the view shown in the widget.

lufecir’s picture

#16 works fine for me too. It's definitely a workaround I can live with. So if it's really a problem to fix this problem at the root, I guess it should at least be documented. A simple additional bullet in the hints when choosing a view as source of the select items would be sufficient. And for those who don't RTFM: well they can still ask google and find this issue. :-)

KarenS’s picture

Status: Active » Fixed

#16 is the right way to do this.

Status: Fixed » Closed (fixed)

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

kiliweb’s picture

Thanks jlevy, #16 works like a charm !

clashar’s picture

jlevy,
your solution #16 is simple and perfect!

Chris Gillis’s picture

Title: How to hide the referenced node title in select list » How to hide the referenced node title in select list with view

#16 works perfectly.

http://drupal.org/node/230298 Marked as Duplicate

Changing title for better findability.

Thanks jlevy

potassiumchloride’s picture

#16 worked for me too. Thanks!

kaod’s picture

#16 didn't work for me but #26 did. I just added the "Node: Title" field and chose "rewrite output" then put a SPACE, like literally hit the space bar and it removed the title from the display.

EDIT: also works by just rewriting the output and inputting nothing in the field, rather than adding a SPACE

newnewuser’s picture

I did #16 too. Thanks.

salberto25’s picture

But only for the title??....I wish to hide any kind of referenced view fields by selecting in the configured fields CCK UI...did I make clear?...