Posted by fallenleaf on June 29, 2009 at 2:14pm
16 followers
| Project: | Content Construction Kit (CCK) |
| Version: | 6.x-2.x-dev |
| Component: | nodereference.module |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
| Issue tags: | autocomplete, limit |
Issue Summary
Version 6.3
For example: 20 node titles include the char "mall".
But when I type the char "mall" in the autocomplete field, only show 10 node in the dropdown.
I need a multiple nodereference fileds. Each one is one of the 20 nodes.
The drupal5 version does it well, the dropdown window include all result. So I can choose any of the 20.
Can the v6 has this feature too?
| Attachment | Size |
|---|---|
| version5 | 8.58 KB |
| version6 | 4.91 KB |
Comments
#1
No body need this feature?
library of brands
#2
CCK is limited by the features of the autocomplete widget provided by Drupal core, which is something that does not provide scrolling, for example. If it needs to be enhanced, then this is a job of Drupal core.
CCK could probably use a higher limit, render 20 instead of 10 items. But there will always be a limit, and we have advanced just a little. So, I think CCK autocomplete might not be an ideal solution for every use case.
Instead, there are alternatives in contrib modules such as Node Relationships that offers a button next to the autocomplete widget that opens a modal dialog with a view that you can customize to "Search and reference".
Making the issue fixed because it seems to me there's little CCK can do here.
#3
Automatically closed -- issue fixed for 2 weeks with no activity.
#4
Why was this marked "Fixed"? It wasn't fixed, it still has the limit of 10. If it isn't going to be changed, then a status of "Won't Fix" would be more appropriate.
I for one think that it absolutely needs to be changed to a higher value. No need for scrolling in an autocomplete field but having more results show is certainly needed.
And if this won't be fixed in the module, can it be explained where this limit is imposed so that those of us that need a higher result can patch our own?
#5
Same problem for me. I need more than 10 nodes to appear on the autocomplete list.
#6
This is how to increase the number of autocomplete suggestions in the taxonomy field.
open file content_taxonomy_autocomplete.module
look for this section
// Fetch last tag
$last_string = trim(array_pop($array));
$matches = array();
if ($last_string != '') {
if ($tid) {
$result = db_query_range(db_rewrite_sql("SELECT t.name FROM {term_data} t
LEFT JOIN {term_synonym} s ON t.tid = s.tid
INNER JOIN {term_hierarchy} h ON t.tid = h.tid
WHERE h.parent = %d
AND (LOWER(t.name) LIKE LOWER('%%%s%%') OR LOWER(s.name) LIKE LOWER('%%%s%%'))", 't', 'tid'),
$tid,$last_string,$last_string,0,10);
}
else {
$result = db_query_range(db_rewrite_sql("SELECT t.name FROM {term_data} t
LEFT JOIN {term_synonym} s ON t.tid = s.tid
WHERE t.vid = %d
AND (LOWER(t.name) LIKE LOWER('%%%s%%') OR LOWER(s.name) LIKE LOWER('%%%s%%'))", 't', 'tid'),
$vid, $last_string, $last_string, 0, 10);
Change both occurrences of 10 to increase the amount of suggestions in the aurocomplete result set
#7
I've implemented something similar as a simple patch for the CCK nodereference module. Rather than hard-coding the new value, I use variable_get(), so I can set the maximum autocomplete size on the fly from elsewhere.
I recommend creating a patch for your changes, so that when you update CCK you can probably just reapply the patch.
#8
Here's another option like #7 but if you don't want to hack nodereference.module... Create a custom module like this (you'll also need a .info file... change 20 to the number you want):
function custom_tweaks_menu_alter(&$menu) {
if (isset($menu['nodereference/autocomplete'])) {
$menu['nodereference/autocomplete']['page callback'] = 'custom_tweaks_nodereference_autocomplete';
}
}
function custom_tweaks_nodereference_autocomplete($field_name, $string = '') {
$fields = content_fields();
$field = $fields[$field_name];
$match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains';
$matches = array();
$references = _nodereference_potential_references($field, $string, $match, array(), 20);
foreach ($references as $id => $row) {
// Add a class wrapper for a few required CSS overrides.
$matches[$row['title'] ." [nid:$id]"] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';
}
drupal_json($matches);
}
#9
I agree with xstatic and jcbou, it should be possible to raise the number of items returned for the nodereference autocomple widget.
That the default autocomplete widget of Drupal doesn't provide scrolling is IMHO not relevant, it's the responsibility of the website builder to keep the maximum number of items reasonable. Please provide such an option, having to put just this small feature in a custom module is a bit of overkill, isn't it?
#10
I would think ideally you'd want this feature to function on a per field basis which would require a fair amount of work from what I can tell. Seems like you'd have to add a new column in the database for field settings, and you have to add the setting to the field settings form. It may be too much of a fringe need for that.
Personally I felt the menu alter wasn't too much work, and is somewhat common for customizing Drupal. People often have to write hook_form_alter()s in custom modules for similar changes.
#11
AFAIK there is no need for an additional database column for each new field setting, I think these are just stored as serialized PHP in the widget_settings column of the content_node_field_instance table.
The menu alter wasn't too much work indeed, but once you need to add 20 reusable modules like that with maximum 2 lines of code changed compared to the original, it starts adding up (thinking about performance and maintainability). I believe it is justified to suspect such basic configuration options to be in the nodereference module itself.
#12
For now I just put the necessary code (based on the code by slip, thanks!) in a module, called nodereference_autocomplete_limit. I added a settings page as well, as suggested by johnpitcairn. So the limit is now configurable (10 till 100, ranges of 5) globally. It does not handle a limit per field currently, as this is not necessary for the project I am working on.
#13
Its been well over a year fallenleaf, but I ran into this module that might help you.
http://drupal.org/project/autocomplete_element
#14
I'm attaching a patch I've been trying out, which makes Node Reference / User Reference fields based on a view takes the number of items configured on the view's default display as the number of items to display in the autocomplete fields. Given that Views default nicely match the 10 that was there before, everything should be working pretty much as in the general case.
This approach doesn't allow users to customize the number of items to display when the fields isn't linked to a view. If it should be allowed, then it probably needs a new settings. That's not a problem in itself, and I'm also attaching a proof of concept patch doing that for Node Reference. If you like this approach best, I'll do the same thing to user reference.
#15
Slip's code in #7 isn't working for me. Does anyone have an alternative? I really need my Node Reference Autocomplete to show the user 20 items. Thank you.
#16
@Q2U2: Have you given any of the patches in #14 a try ? The more I think about it, the more I like best the second approach.
#17
DeFr, thank you...yes...I just applied your Path #2 (cck-505272-autocomplete_results_count_with_settings.patch 2.27 KB) and I am having the same issue with your patch that I had when I tried Slip's #7 code.
Here is the problem:
The problen is that only 10 results are showing...BUT there ARE 20 results present because I can arrow down to select results 11 to 20 (even though I can't see them).
Do you understand? I'm thinking this may be some sort of CSS issue?
Here is what I see...
http://www.zombiesmustdie.com/img/external/mim/nodereference.jpg
Help?
#18
*BUMP* DeFr: any comments on my last post?
#19
Looking at your screenshot, yes, what you have left is a CSS problem; something's cutting the autocomplete dropdown at the boundary of the node form, which means that you can't see all your results. The attached patch won't deal with it, and I don't really think it should be the same issue, given that the autocomplete only shows 9 of the 10 results that it should already get by default.
I think you should be able to solve your problem with some simple rules on #autocomplete in the CSS of your theme, taking it out of the page flow, but that will depend on your theme.
(An obvious alternative would be to move your fields somewhere higher in the form, but I suppose that's not possible for you)
#20
Thank you for your reply DeFr. The Theme I am using is Aquia Marina. If I change my Theme to Garland then I see all 20 results. But for the life of me I can't figure out what Acquia Marina CSS is limiting the display of my AutoComplete results to 10. (
Grrrr...
#21
Thanks Cyberwolf!
Tried changing the 10 to 100 manually (hacked the module) but for some reason that didn't work (I even reinstalled the autocomplete module + flushed cache a number of times).
I even changed the limits in your module (#12) and it worked flawlessly!
#22
This #505272-8: The result of autocomplete does not include all workaround works for me
#23
I tried #8 and it didn't work for me but I figured a work around. I'm using view3 and my CCK nodereference field was being filter with a view. There is a issue in nodereference.module if you are using views3. So you can patch it like:
http://drupal.org/node/1065128#comment-4184964
or you can do this workaround in your own code:
1) add in yourmodule_potential_references function modeled after _nodereference_potential_references
a) change _nodereference_potential_references_views to yourmodule_potential_references_views
2) add in yourmodule_potential_references_views function modeled after _nodereference_potential_references_views
a) change
$view->display_handler->set_option('items_per_page', $limit);to
$view->set_items_per_page($limit);3) change your mymodule_nodereference_autocomplete to use:
yourmodule_potential_references
instead of
_nodereference_potential_references
Now the limit will be passed to views properly.
#24
I'd just like to report that I had a problem similar to the title of this issue. I had a node that would not show itself in the auto complete field. During my testing, I utilized the Network tab in Firebug to watch what was going on. Oddly enough, I could see the node in question being included in the JSON result object, but it would never show itself in the auto complete popup. Ultimately I had to delete the node and re-create it to get it to show up in the auto complete listing.