contao/test — Issue #2973: Force options to be associative
Author: importer
Created: 2011-11-29 10:44:33+00:00
State: open
Labels: backend, Feature

Hi Leo,

Controller::prepareForWidget checks if the options of a select widget are stored in an associative array or not. If it is not an associative array, the option value is the key of the array entry otherwise it is the same as the value of the array entry.
Sometimes I don't want the values be the keys e.g. if I want to save data for statistical calculations. This all works fine if I don't start my data values with the index 0, in this case the array is recognized as non-associative and the array values are used for the option values.

Example:

I can never have an array
{
0 => "Value nil",
1 => "Value one",
2 => ...
}

in a select field with

Value nil

Value one

....

Instead you get

Value nil

Value one

....

because the array is recognized as non-associative. If I start my indexes with 1 instead of 0 it works. But sometimes I need my values start with 0.
I would like to propose an extra eval setting or field setting

forceAssociative - true/false

to force an options array to be treated like an associative array to get option values starting with 0.

Cheers,
Helmut

--- _Originally created by hschottm on June 21st, 2011, at 04:58pm (ID 3185)_