Okay, so I have a CCK decimal field that needs to only be allowed to be one of the following values: 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0.

However, entering those values into the 'Allowed Values' box results in the following error when I try to change set the field's value to, say, 4:

* warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in /home/squashju/public_html/dev/sites/default/modules/cck/modules/number/number.module on line 236.

* Skill Level: illegal value.

The offending code is the following line:

if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
              form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label']))));
            }

A printout of $allowed_values and a printout of $items produce the following arrays:

$allowed_values: Array ( [2.0] => 2.0 [2.5] => 2.5 [3.0] => 3.0 [3.5] => 3.5 [4.0] => 4.0 [4.5] => 4.5 [5.0] => 5.0 [5.5] => 5.5 [6.0] => 6.0 )

$item: Array ( [value] => 4 [_error_element] => field_sp_skill][0][value )

Is there some different way I should be setting allowed values for a decimal field such that they work, or is it just a number.module bug that needs to be fixed?

CommentFileSizeAuthor
#2 cck-numeric-validation.patch740 bytesMoonshine

Comments

yched’s picture

Status: Active » Fixed

Indeed. Fixed in -dev.

Moonshine’s picture

Status: Fixed » Needs review
StatusFileSize
new740 bytes

I think there may be an issue with the fix, it looks to be checking the $value rather then the $key.

Attached patch fixes things for me..

Moonshine’s picture

Version: 6.x-2.0-rc6 » 6.x-2.x-dev

Opps.. this is against dev now...

yched’s picture

Status: Needs review » Fixed

Doh, you're right. Fixed now. Thks !

relaxatorium’s picture

Is this fixed in RC7 as well, or only in dev?

I want to double check, before I upgrade.

yched’s picture

no, that went in post RC7 (both my original fix and Mooshine's fix for the fix)

Moonshine’s picture

It's just in dev right now, but if you're grabbing the tarball from :

http://drupal.org/node/266142

You'll want to wait until it's updated with today's date. If you get it via CVS it will be fresh.

relaxatorium’s picture

So, if I just want to fix this without swapping fully to the dev version then, could I just replace the line of code I quoted above with Moonshine's attached patch?

That seems to be the thing to do, but I am not a Drupal module developer expert, so I wanted to make sure before doing it.

yched’s picture

If you want just that change, you'll need to take the content of number_field() function from http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/cck/modules...

relaxatorium’s picture

Thanks so much for your help. I'm glad I was able to help bring this to light.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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