Posted by Ben Scott on November 27, 2008 at 11:58am
Jump to:
| Project: | CCK Node Reference ASM Select |
| Version: | 5.x-1.0-rc4 |
| Component: | User interface |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Hi -
I've got sortable turned on for my asm node select field, and the sort does seem to be working: I can change the node order in the asm, save it and the order is saved. But when I go back in and edit the node the asm select list doesn't reflect the node order - it just uses the default sort?
Do you know what might be causing this?
Thanks very much,
Ben
Comments
#1
I see the same problem. That makes the widget quite unusable. :(
#2
I checked this a bit further. The order is saved (and when I change to another widget, it is also displayed on the edit form), but when loading the edit form, the JS gets the nodes in the default order.
#3
I think it is because the field is generated as $nodereference_field['widget']['type'] = 'nodereference_select';
The nodereference module seems to ignore the delta on nodereference_select fields and only use it on autocomplete fields.
I think we have to generate the list of options ourselves, just like the multiselect widget does.
#4
I'm pretty sure that it worked for me during development, otherwise I wouldn't have used this method. Anyways, I've written a function to generate the list when using filters, might as well use it when not using filters as well.
Unfortunately, I'm totally backed up with work for the next two weeks or so. I'd love some help with this. Nath - would you like to have CVS access and try to fix some of the issues you've submitted?
#5
If that would speed up things, yes.
#6
You'll have to create a CVS account. Contact me directly (shai.yallin@ewave.co.il) once you have one, and I'll grant access.
#7
CVS Account application approved.
#8
@nath - CVS access granted.
Don't hesitate to contact me directly if you need assistance.
Thanks :)
#9
Ok, back to working on this problem.
In "function nodereference_asmselect_widget($op, &$node, $field, &$items)" we've got the following lines at the beginning:
<?php
$nodereference_field = $field;
$nodereference_field['widget']['type'] = 'nodereference_select';
$ret = nodereference_widget($op, $node, $nodereference_field, $items);
?>
the way nodereference_widget works, the values in $ret are already in their default order, as delta is ignored for nodereference_select types.
I cannot identify the function you are talking about, could you give me directions?
#10
Ok, currently, I'm using Node Reference's original implementation for creating the options list. This is because at first there were no filters in this module, and this seemed like the a good idea - reusing Node Reference's code, making things simple, etc.
However, since we now have filters, we have a bit of a mess. The initial options list is indeed generated by Node Reference, but any further filtering request will re-create the list using nodereference_asmselect_options (it's a menu callback, outputting only the options list using AHAH).
So, the best idea would be to remove the dependency on Node Reference's widget generation, copy all needed functionality from there and then generating the options list ourselves using _nodereference_asmselect_get_filtered_options for the initial list as well. This means:
1) Major changes to nodereference_asmselect_widget - essentially duplicating lots of code from nodereference.module.
2) More dependency on Views (as _nodereference_asmselect_get_filtered_options uses a programmatically-built view in order to generate the node list).
3) Lots of testing.
HOWEVER - I'm pretty sure that Node Reference does NOT ignore the 'delta' field, otherwise this would've come up during development. I suggest that you have another look at the way the field data is loaded (I think that it's done by content.module itself), maybe the solution is simpler than a total refactor of this module. Keep in mind that this module was initially supposed to be a lightweight adapter for asmSelect, nothing more.
#11
Ok, the real problem seems to be the following:
The base field for the Javascript is a "select" field. this select field gets its options in some standard order, changing the order of the default options doesn't influence this.
What one has to do I've seen in the multiselect module:
<?php
$options = _nodereference_potential_references($field, TRUE);
foreach ($options as $key => $value) {
$options[$key] = _nodereference_item($field, $value, FALSE);
}
$selected_options = array();
//If there already exists referenced nodes for this field, add them
// to the selected options array (by order of their delta)
if (is_array($items['default nids']))
{
foreach($items['default nids'] as $delta => $nid)
{
$selected_options[$nid] = $options[$nid];
}
}
//anything in $alloptions but not in $selectedoptions is "not selected"
$not_selected_options = array_diff($options,$selected_options);
//reassign $options to reflect delta.
//note: No new options are created in this list,
//but putting selected options first ensures the form is populated in
//the order of (thus maintaining) its deltas.
$options = $selected_options + $not_selected_options;
?>
Doing this keeps the order of the default options and thus keeps the order of the nodes in our Javascript.
#12
Having the same problem.
#13
THANX!!!!!!!!!!!!!!!!!!!!!!!!!!
THANX!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I've inserted your code in nodereference_asmselect.module, line 223, after
if (array_key_exists(0, $options)) {
unset($options[0]);
}
... START PATCH ....
and it's OK!!!!!
#14
Like diego.paroni I inserted your code and have the module mostly working. One thing that is still broken with this hack however is form validation. If the form does not pass validation and reloads with errors, the sorting is lost.
I need to get this fixed in the next couple days, so I will post a patch here if I figure it out.
--kevin