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?
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | cck-numeric-validation.patch | 740 bytes | Moonshine |
Comments
Comment #1
yched commentedIndeed. Fixed in -dev.
Comment #2
Moonshine commentedI 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..
Comment #3
Moonshine commentedOpps.. this is against dev now...
Comment #4
yched commentedDoh, you're right. Fixed now. Thks !
Comment #5
relaxatorium commentedIs this fixed in RC7 as well, or only in dev?
I want to double check, before I upgrade.
Comment #6
yched commentedno, that went in post RC7 (both my original fix and Mooshine's fix for the fix)
Comment #7
Moonshine commentedIt'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.
Comment #8
relaxatorium commentedSo, 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.
Comment #9
yched commentedIf 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...
Comment #10
relaxatorium commentedThanks so much for your help. I'm glad I was able to help bring this to light.
Comment #11
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.