Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multicheckbox label #17

Open
Perfect-Web opened this issue Mar 29, 2015 · 6 comments
Open

multicheckbox label #17

Perfect-Web opened this issue Mar 29, 2015 · 6 comments

Comments

@Perfect-Web
Copy link

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

@cgmartin
Copy link
Owner

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'),
),

@Perfect-Web
Copy link
Author

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

@cgmartin
Copy link
Owner

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

@Perfect-Web
Copy link
Author

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

@Perfect-Web
Copy link
Author

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

@cgmartin
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants