Can I hide or remove [nid:n] in node reference fields so only title is shown?
related forum requests:
http://drupal.org/node/487554
http://drupal.org/node/364768
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | jquery_autocomplete-6.x-1.1_chrome_fix.tar_.gz | 980 bytes | threexk |
| #17 | autocomplete_error.jpg | 78.31 KB | tmckeown |
| #10 | jquery_autocomplete-6.x-1.1.tar_.gz | 874 bytes | shaunjohnston |
| #7 | jquery_autocomplete.tar_.gz | 831 bytes | shaunjohnston |
Comments
Comment #1
markus_petrux commentedThis is not possible because node titles may not be unique. I'm sure this had been discussed in this queue a few times.
Comment #2
giorgio79 commentedThanks Markus, I believe this request is still valid.
Having nodes with identical titles is bad design and practice...
Comment #3
giorgio79 commented#157545: Have [nid:n] hidden from user
Comment #4
fourmi4x commentedThis link is for Drupal 7... but what about Drupal 6 ?
With the module http://drupal.org/project/unique_field one can ensure that all titles are unique, so this problem seems to be resolvable.
Has anyone find a solution to hide the [nid:n] ?
The best I've found is here : http://drupal.org/node/784048, and it doesn't seem to work...
Comment #5
fourmi4x commentedRe-opening the issue for drupal 6
Comment #6
NathanM commentedWhat about, instead of placing the title and node id in the same field, if you could somehow modify node reference to place the node id in a separate field which can optionally be hidden. That way, the node id would still be referenced, but the average user wouldn't see it.
Comment #7
shaunjohnston commentedI encountered this issue today and have hacked together a simple module (attached) that implements a pure javascript solution.
The way I solved it is fairly brute-force. I preload a handler that transforms each autocomplete field by
This is my first attempt at an integrated Drupal jquery object (until now I have been simply bolting plugins onto jQuery rather than Drupal), and it's possible I may be doing some things incorrectly. The main thing for me though is it works!
With some more work it could probably be made more fine-grained and controllable.
Hope this helps someone out.
Module code is as follows:
Javascript is as follows:
Comment #8
tmckeown commentedI didn't have any luck with this. I see the addition hidden input it adds but the text field still displays the node id.
Comment #9
shaunjohnston commented@tmckeown seems my javascript fails in Internet Explorer (works in Chrome / Firefox). I'll track down the problem. Thanks.
I have created a basic drupal install (latest stable d6) as a proof of concept for the module. It has cck installed with node references enabled, filefield, and my jquery_autocomplete module. Other than that, it's clean.
I've created two content types, Item and Reference - Item contains an autocomplete nodereference field, which references the Reference content type.
Anyone can visit this site and create content here: http://nrj.sjnstn.me
Comment #10
shaunjohnston commentedHere is an updated version of the module with Internet Explorer support. I made the old error of neglecting to cater for IE's odd change behaviour. The autocomplete widget doesn't seem to trigger a 'change' event for the element in IE.
The solution is to set a 'changed' flag to false, and on a blur event trigger the change event so that IE notices the value has changed. Then, the change event sets 'changed' to true, then again triggers blur. IE sees the new value and does the forwarding to child element and stripping. The blur event then sets sets 'changed' to false again for next time. I have used $.browser.msie to detect IE on blur - otherwise the additional change trigger is bypassed.
Also, I noticed I had jquery_ui listed as a dependency in the module. That's not actually true, so I have removed that line.
Comment #11
fourmi4x commented@sdj : I've tried your demo website, it works perfectly indeed!!
Many thanks for working on that, this goes far beyond my knowledge...
I wonder if this would work with the noderelationship module ? (for instance with the selection of the nodes in a modal frame).
I'll try it and come back to you!
Comment #12
fourmi4x commentedWell it works perfectly on my installation (which have looots of modules, including Node Relationships, jQuery UI, jQuery Update), many thanks !
I think you cracked down something that got on the nerves of many drupalers...
Comment #13
shaunjohnston commented@fourmi4x: good to know it's working in the wild. It blows my mind that this has been talked about since 2007.
Comment #14
fourmi4x commentedThis is mad indeed !!
Comment #15
fourmi4x commentedHi,
I just noticed a compatibility problem:
I installed the Active Tags module and have a very strange behaviour : The drop-down of the Active Tags fields appears just a fraction of second and then disappears, so I have to be rapid as hell if I want to select something...!!
NB: after the drop-down disappears, the focus does not stay inside the input box.
This does not happen when the Active Tags module is disabled, or when jQuery Autocomplete is disabled and Active Tags enabled.
I have noticed this behavior also affects the drop-down of nodereference fields when Active Tags is enabled, which otherwise work well when Active Tags module is disabled.
I guess this might be a conflict between the jQuery scripts of the two modules...?
Comment #16
shaunjohnston commented@fourmi4x My guess is my module's autocomplete selector needs to be more granular. Will take a look soon. Thanks!
Comment #17
tmckeown commentedsdj,
Thanks for your efforts on putting this together. I noticed on your site I am getting a form validation error when I created an item with a reference. The error is "reference field is required". Also I noticed that on your site the [nid:\d+] still appears. I am using Drupal 6.20, CCK 6.x-2.9, and Firefox 3.6.13. Attached is a screen shot.
Comment #18
shaunjohnston commented@tmckeown Interesting - I just tried the form on nrj.sjnstn.me with firefox 3.6.13, and it worked for me. This is going to be difficult to track down.
Comment #19
fourmi4x commented@logicalor : Did you have a chance to look at this conflict with the Active Tags module / this problem of granularity ?
Would love to use both your module and Active Tags, that would make an awesome edit form!
Comment #20
fourmi4x commentedI found another incompatibility, which is in fact much more important: the autocomplete of Solr search form doesn't work any more when this module is enabled.
The search always redirects to the base url (http://www.website.com/search/apachesolr_search/) whatever we type in the search box (If we type "searchedword", it should redirect to http://www.website.com/search/apachesolr_search/searchword)
Any idea about this? This is very crucial to me...!
EDIT : Is there an easy way to make this module only apply to nodereference fields ?
Comment #21
fourmi4x commentedOk, in order for this patch to only apply to NodeRelationships autocomplete fields, one can simply replace 5 times
.form-autocompleteby.noderelationships-nodereference-autocompletein the jquery_autocomplete.js file... I guess something similar can be done with normal nodereference fields.
Hope that helps, thanks again for this awesome module!
By the way, doesn't it deserve a dedicated page on drupal.org? I guess lots of people are looking for this... and maybe it could be further improved?
Comment #22
dcine commentedI have a content type with a nodereference field. I want to hide the [Nid] of this field.
I tried to install the module of "Logicalor"
Hides the Nid, but it generates the same problem that says "tmckeown. "
On the webpage I have more content types with "nodereference" fields.
If I install the module, nodereference fields of these content types fail.
Is there anyone who has found the solution?
How could I make will only affect this type of content and not the rest?
Any help? Please!
In any case
A salute to the community
Comment #23
willhowlett commentedGreat module. Many thanks. Agree it deserves it's own dedicated module page
Comment #24
threexk commentedRe #10: Great module, but doesn't work in Chrome.
Comment #25
threexk commentedIn Chrome, when you select a node, it still shows the [nid:n] in the text input with the jquery_autocomplete module. However, you can make it disappear if you manually focus/blur the field. (That is, click on the text input and then click somewhere else.) Not sure how to fix this problem.
Comment #26
fourmi4x commentedI confirm the bug. When using the "add" feature of Node Relationship module, the nid is well hidden. However, the nid is shown when clicking on a suggestion of the autocomplete, in Chrome. I'm a total js newbie, so don't know how to fix this too...
Comment #27
willhowlett commentedOne query I have about this module is the fact that it chooses to move the real data to a new hidden form element, then displays the stripped data in the original form element. Would it not make more sense to hide the original form item and display a dummy stripped element? This would keep the original form data intact.
The reason I ask is that the module seems to break the functionality of the node reference create module (http://drupal.org/project/noderefcreate) which I assume is because the noderefcreate module is looking for a NID in the original field, but using this module the NID is in the dummy field. Would assume this would cause problems with other modules as well, but perhaps there is a technical reason for doing it the current way?
EDIT: Ignore the above, this way round does make sense. I was able to fix my specific conflict by simply commenting out the if statement on line 39 of jquery_autocomplete.js (leaving the actual contents of the if statement intact). This means it copies the contents of the select box over to the 'real' hidden element even if it doesn't have a NID, which is exactly what you want if using the noderefcreate module.
Really think this module needs it's own project page, I can see this thread getting a bit overcrowded :)
Comment #28
threexk commentedI am offering a 20 USD bounty to fix the issue described in #25. It might be a simple fix. Please see the following page if interested:
http://drupal.org/node/1220028
Comment #29
threexk commentedThanks to arpeggio for providing a fix to the Chrome bug and collecting the bounty. arpeggio also fixed the module to work when selecting items using up/down arrow keys. Updated module attached (apologies, I messed up the JS code formatting).
Comment #30
tlangston commentedModule works but broke Views DDBlock slideshow - specifically ddblock. Disabled for now.
Comment #31
manuel.adanUsed in a node reference field inside a multigroup module doesn't close pop-up dialog.
Comment #32
fourmi4x commentedUsing module in #29, I came up with 2 bugs:
I am offering a 30 USD bounty to fix these issues, which might a simple fix of the previous fix... Please see the following page if interested:
http://drupal.org/node/1320960
Comment #33
halloffame commentedInstalling #29 disabled all my fieldset around site.
Comment #34
fourmi4x commentedThis issue finally has its dedicated project page, thanks to arpeggio!
He did a lot of work, and most of the issues mentioned above are now fixed.
Here is the link to the project page: http://drupal.org/project/nodereference_nid_trim
Comment #35
hgneng commented>http://drupal.org/node/784048
This works well for me on D7. But there is another place need to modify. Just search "[nid" in the file and comment out following code:
$value .= ' [nid:' . $nid . ']';
Comment #36
razkovnik commentedYes, this works at me also on D7.