The code above in number.module on line 232 is not considering the use of optgroups in select's.

foreach ($allowed_values as $kay => $value) {
	if ((float) $item['value'] == (float) $kay) {
		$valid = TRUE;
		break;
	}
}

When using optgroups $kay is an array, causing the invalid error message (illegal value).

I think the code above will correct the issue.

foreach ($allowed_values as $kay => $value) {
	if (is_array($value))
	{
		foreach ($value as $k => $v) {
			if ((float) $item['value'] == (float) $k) {
				$valid = TRUE;
				break;
			}
		}
	}
	else
	{
		if ((float) $item['value'] == (float) $kay) {
			$valid = TRUE;
			break;
		}
	}
}

Comments

markus_petrux’s picture

Status: Active » Closed (duplicate)

Oh, I see. It seems support for optgroups was not as easy as it seemed.

Please, see: #521002: Support for optgroups in allowed values for select elements

markus_petrux’s picture

Patch posted at #521002: Support for optgroups in allowed values for select elements.

Please test, if you have the chance. Thanks. :)