CgmConfigAdmin icon indicating copy to clipboard operation
CgmConfigAdmin copied to clipboard

multicheckbox label

Open Perfect-Web opened this issue 10 years ago • 6 comments

How can we specify label for each value in a multicheckbox ?

Perfect-Web avatar Mar 29 '15 11:03 Perfect-Web

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 avatar Mar 29 '15 14:03 cgmartin

@cgmartin i tried, doesnt work, also if you have multiple values selected, it only returns 1 value, not all the selected values

Perfect-Web avatar Mar 29 '15 15:03 Perfect-Web

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"
}

cgmartin avatar Mar 29 '15 16:03 cgmartin

sorry about that, was a false alarm, turned out the config was cached :( ....

Perfect-Web avatar Mar 29 '15 20:03 Perfect-Web

@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'));
    }

Perfect-Web avatar Mar 31 '15 17:03 Perfect-Web

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.

cgmartin avatar Mar 31 '15 19:03 cgmartin