multicheckbox label
How can we specify label for each value in a multicheckbox ?
I think you can supply value_options with an assoc array (key => value, value => label). Internally I believe it calls setValueOptions(): http://framework.zend.com/manual/current/en/modules/zend.form.element.multicheckbox.html
i.e.:
'multiCheckboxOption' => array(
'input_type' => 'multicheckbox',
'label' => 'MultiCheckbox Option',
//'value_options' => array('Foo', 'Bar', 'Dev', 'Null'), // value and label are the same
'value_options' => array('foo' => 'Foo Label', 'bar' => 'Bar Label'), // value and label are different
'default_value' => array('foo'),
),
@cgmartin i tried, doesnt work, also if you have multiple values selected, it only returns 1 value, not all the selected values
I can't replicate this behavior, it works for me with ZF 2.1.4 and 2.3.7. Here is the config I used: https://gist.github.com/cgmartin/02a939557c9517a8830e#file-cgnconfigadmin-global-php-L61
And the getConfigValue which returns multiple selected values:
https://gist.github.com/cgmartin/02a939557c9517a8830e#file-indexcontroller-php
array(4) {
[0] => string(3) "foo"
[1] => string(3) "bar"
[2] => string(3) "dev"
[3] => string(4) "null"
}
sorry about that, was a false alarm, turned out the config was cached :( ....
@cgmartin i just realized it works only if you have as key a non-numeric string, basically i cant make this work because i need the values to be integers and not strings. is all related to this function
protected function isAssocArray($arr)
{
return (bool)count(array_filter(array_keys($arr), 'is_string'));
}
IIRC, by default, the input elements operate off of string type values for the options (since that is what they are ultimately rendered and received as via the web page as HTML). There are "filters", that can be used to convert the data, but I doubt they are supported in this project. PRs are welcome, but as a workaround you might consider converting to int manually when retrieving.