Skip to content

Add block to collection_check_boxes and collection_radio_buttons. #477

Open
@lcreid

Description

@lcreid

The Rails collection_check_boxes and collection_radio_button methods can take a block. If a block is provided, the helper yields a special builder to the block. The idea is that the programmer can format the check box or radio button more precisely in the block, if the standard format produced by the Rails helpers doesn't give the desired results.

Our helpers do not take a block. We can speculate that since our helpers format the check boxes and radio buttons in a consistent and pleasing way, there's less need for the block. There may also have been a technical reason that made yielding to a block difficult. I haven't investigated enough to have an idea of that.

However, there still may arise situations in which it would be convenient to have the ability to output the controls in a block. On example would be when you want to show all the check boxes or radio buttons, but some of them need to be disabled. Another example might be to highlight certain "dangerous" check boxes or radio buttons with the "danger" colour.

Another argument in favour of providing this is simply to make our helpers more closely mimic the behaviour of the Rails helpers. I bet there are a number of cases of people wasting an hour or two trying to get a block to work with our helpers before they realized that our helper doesn't work that way.

One alternative is for programmers to code the loop themselves. This is probably not a large burden, although they would have to remember to add the div.form-group and the error handling in order to be 100 percent compatible with our helpers.

Would we consider a pull request for this functionality if someone submitted one?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions