2.3 FormHelper::radio enhanced options #1032

wants to merge 2 commits into

3 participants

  • add 'afterOption' and 'beforeOption' options, in order to generate more content witihn a radio set. For instance, encapsulate the pair 'label' + 'input' within a 'li'.
  • this 2 can uses the options data to generate content, through sprintf format (%1$s will be the key, while %2$s will be the title of the option), for instance adding an 'img' attached to each option.

See unit tests for examples of usage.
I'll update the documentation once these are accepted.


might be related to #864

CakePHP member

Why not expose this as one option 'wrap' that defines the wrapping content for a radio button? Using some simple sprintf() formatting should work fine for this kind of use as there are only two elements that would need to be inserted into the wrapping html.


One other use case is to add pictures and links, related to each option, to illustrate them or suggest more information.
This one case can be seen in action in the tests.

I would suggest that 'afterOption' and 'beforeOption' allows for more flexibility than one 'wrap' option.

CakePHP member

But only adding one option keeps the API smaller, requires less mental memory to remember the names of all the options, fewer tests, and less documentation.

CakePHP member

For example the test that contains a link/img could be written as:

$result = $this->Form->radio(
      array('A' => 'option A', 'B' => 'option B'),  
        'wrapInput' => '<img src="/img/:value.png" alt=":title" />:input<a href="/option/:value">learn more about :title</a>',

The above would use String::insert()/strtr as it is easier to read than sprintf when there are many values being inserted. I'm hoping to coalesce many of the existing options to this style for 3.0 as the existing pile of format/append/prepend options have gotten out of control.

@lorenzo lorenzo closed this Jan 28, 2013
CakePHP member

Please reopen targeting the 2.4 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment