Attempting to save any type of 'Select (or other) drag and drop lists' field for content type logged the following errors:

  • Notice: Undefined index: #field_name in select_or_other_field_widget_validate() (line 267 of /.../modules/select_or_other/select_or_other.field_widget.inc).
  • Notice: Undefined index: #field_parents in field_widget_instance() (line 568 of /.../modules/field/field.form.inc).
  • Notice: Undefined index: #field_name in field_widget_instance() (line 568 of /.../modules/field/field.form.inc).
  • Notice: Undefined index: #language in field_widget_instance() (line 568 of /.../modules/field/field.form.inc).

Comments

danielb’s picture

Confirmed, plus the ordering seems to get lost?
Had a quick look, couldn't figure it out.

danielb’s picture

I have another module with this functionality, I will check if it's working there.

danielb’s picture

It works in Block Reference, I'll try to see what could be different in the code...

danielb’s picture

bah it's done a totally different way, will try to just find a fix for the current way it works

danielb’s picture

I got rid of the error by changing this line ~334 in select_or_other.field_widget.inc

$instance = field_widget_instance($element, $form_state);

to this

$instance = $form_state['field'][$element['#parents'][0]][$element['#parents'][1]]['instance'];

it's a bit iffy

danielb’s picture

and doesn't fix the ordering issue

the info about the ordering comes through in the validate function at
$element['_weight']['#value']
but I've never had to specifically handle it before so not sure

I wonder if there are some other modules that use drag and drop ordering I could check

Rory’s picture

Version: 7.x-2.8 » 7.x-2.9

After applying your change in #5 an error still occurred so I changed the start of the function from:

/**
 * Element validate callback for a Select (or other) field widget.
 */
function select_or_other_field_widget_validate($element, &$form_state) {
  $field_info = field_info_field($element['#field_name']);
  ...

to:

/**
 * Element validate callback for a Select (or other) field widget.
 */
function select_or_other_field_widget_validate($element, &$form_state) {
  $field_name = $element['#parents'][0];
  $field_info = field_info_field($field_name);
  ...

Then your:

  $instance = $form_state['field'][$element['#parents'][0]][$element['#parents'][1]]['instance'];

can become:

  $instance = $form_state['field'][$field_name][$element['#parents'][1]]['instance'];

which looks nicer. But about this:

and doesn't fix the ordering issue

If you mean the checkbox "Sort options - Sorts the options in the list alphabetically." I checked that and it appears to sort the select list on the content type creation form. So yeah - maybe that's working? Am I supposed to be seeing a plain old select list there, though? Or a list of drag and drop items... because it's just a plain select list. But it sorts alphabetically (by value) when the checkbox is checked, and doesn't sort when the checkbox is unchecked. Which is good.

It would help to update the description "Sorts the options in the list alphabetically." to "Sorts the options in the list alphabetically by value." just to make this clear to an administrator before they select it.

danielb’s picture

I meant the ordering that happens when you drag and drop the items. I think that's meant to work automatically but it doesn't.

BTW The sorting you're talking about isn't actually alphabetical sorting it is a "natural order" algorithm which means nothing to most people, so saying alphabetic wouldn't be correct.

Rory’s picture

Alphabetical... natural order... I only suggested adding "by value" to the description. It's not my writing otherwise.

It would be helpful to indicate sorting applies to values, and not keys. Rather than not indicating either way.

rsgracey’s picture

Would someone please roll us up a patch for this module, so that we can make it official? I've just started having this same error, and I'd like to test a patch.

Rory’s picture

Version: 7.x-2.9 » 7.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new1.5 KB

Patch attached contains the fix, and the 'Sort options' elaboration on sorting by value.

ilechcod’s picture

I'm getting the same errors.
Please how do I install this patch?

Rory’s picture

Windows patching: http://drupal.org/node/620014
Mac OS X patching: http://drupal.org/node/60818

Because the "patch" command is a Unix command—not a Drupal command or a Windows command—Windows users need to utilize a tool that allows them to run Unix commands.

So... once the "patch" command is operational for you, type "patch --help". That will list some very helpful examples.

danielb’s picture

If you use git there are specific instructions for patching this module available on the project page if you click 'version control' up the top.
If we get more positive feedback I will be happy to commit.

danielb’s picture

Status: Needs review » Fixed

In there interest of speeding this issue up I have committed the patch. I find it likely that it will work, but if anyone notices any side effects I guess we'll have to revisit this.

Rory’s picture

@danielb - for future reference, under a user's profile you'll find an instruction on how to pass authorship attribution to that user, via 'git commit'.

A number of patches you've applied in the past could have had authorship attributed to other users. If you fail to do this in future, authorship of patches will continue to be attributed to yourself! :-)

danielb’s picture

Oh sorry dude, I thought writing your username into the commit message would cover it. I learnt maintaining modules back in the CVS days.

Status: Fixed » Closed (fixed)

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

  • Commit 5bc3928 on 7.x-2.x, 7.x-3.x, 8.x-3.x by danielb:
    Issue #1494980 by Rory: Undefined index error using drag and drop lists...