-
Notifications
You must be signed in to change notification settings - Fork 22
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
How to set which item in a select collection is pre-selected? #153
Comments
The govuk_collection_select method, which is a wrapper for Rails' collection_select, was missing documentation for the `options` and `html_options` keyword args. They are passed through to the wrapped method directly. The spec covers example use of pre-selecting an option and ensures attributes are correctly set. Refs #153
Hi David. This is possible but your issue highlighted a shortfall in the docs which I've fixed in dbfdc6c. I think the cleanest solution is to add your options to a collection object and pass it into Let me know how you get on. If for some reason this approach isn't suitable I think there would be a case for implemeting |
Setting Namely, I want to set the class of the resulting select, but something seems to eat the class option somewhere along the way. I have tried adding |
More specifically: Currently, we apply classes and other attributes (e.g. That might cash out to two separate issues: one to be able to add classes to the containing div, and one to add attributes to the select. We'd like to have both so we can replicate what we already have here (pre-GDS Formbuilder). Both are requirements for GDS Formbuilder to be usable in this case (we use it elsewhere on our service). We want to be able to do something vaguely like this: = f.govuk_collection_select :radius,
radius_filter_options,
:second,
:first,
label: { text: t('jobs.filters.within_radius') },
# Going off the rails from here onwards
selected: @vacancies_search.radius,
disabled: @vacancies_search.disable_radius?,
div_classes: 'govuk-!-width-full', # applies to the div.govuk-form-group
select_classes: 'govuk-inset-text' # applies to the select |
Ah, classes supplied in I'm slightly reluctant to add support for setting classes on the form group, it's a much bigger change - we'd want consistent behaviour across all helpers that wrap their content in a However, if there's a widespread need for it, it can be done. For the moment I'd suggest wrapping the .full-width-wrapper > .govuk-form-group {
// blah
} |
Previously the classes were overwritten when the form builder's options were merged into the supplied HTML options Refs #153
Previously the classes were overwritten when the form builder's options were merged into the supplied HTML options Refs #153
The Rails helper options_for_select takes a second argument which specifies which collection item is selected, allowing us to dynamically and automatically set it depending on e.g. the user's previous selection, saving them time.
I can't see a way to achieve the same outcome using GovUK Design System Formbuilder. This means that migrating our form to GovUK Design System Formbuilder would be a regression in user experience. Does a way exist to achieve this?
The text was updated successfully, but these errors were encountered: