<% described_by = local_assigns[:described_by] || "" form_group_classes = class_names( "govuk-form-group", local_assigns[:formGroup].try(:[], :classes), "govuk-form-group--error" => local_assigns[:errorMessage].present? ) select_classes = class_names( "govuk-select", local_assigns[:classes], "govuk-select--error" => local_assigns[:errorMessage].present? ) select_attributes = { class: select_classes, id: local_assigns[:id], name: local_assigns[:name], "aria-describedby": described_by.presence } select_attributes.merge!(local_assigns[:attributes]) if local_assigns[:attributes] %> <%= tag.div(class: form_group_classes) do %> <%= govukLabel( html: local_assigns[:label].try(:[], :html), text: local_assigns[:label].try(:[], :text), classes: local_assigns[:label].try(:[], :classes), attributes: local_assigns[:label].try(:[], :attributes), for: local_assigns[:id]) %> <% if local_assigns[:hint] %> <% hint_id = local_assigns.try(:[], :name) + '-hint' described_by = described_by.present? ? described_by + ' ' + hint_id : hint_id hint_classes = class_names( "govuk-hint", local_assigns[:hint][:classes] ) %> <%= govukHint({ id: hint_id, classes: hint_classes, attributes: local_assigns[:hint][:attributes], html: local_assigns[:hint][:html], text: local_assigns[:hint][:text] }) %> <% end %> <% if local_assigns[:errorMessage] %> <% error_id = local_assigns.try(:[], :name) + '-error' described_by = described_by.blank? ? error_id : "#{described_by} #{error_id}" error_attributes = (local_assigns[:errorMessage][:attributes] || {}).merge(id: error_id) %> <%= govukErrorMessage({ id: error_id, classes: local_assigns[:errorMessage][:classes], attributes: error_attributes, html: local_assigns[:errorMessage][:html], text: local_assigns[:errorMessage][:text], visuallyHiddenText: local_assigns[:errorMessage][:visuallyHiddenText] }) %> <% end %> <% select = capture do %> <%= tag.select(**select_attributes) do %> <% local_assigns[:items].each do |item| %> <% option_attributes = { selected: item[:selected] || (!local_assigns[:value].nil? && item[:value] == local_assigns[:value]), disabled: item[:disabled], value: item[:value] } item_attributes = (item[:attributes] || {}).merge(option_attributes || {}) %> <%= tag.option(item[:text], **item_attributes) %> <% end %> <% end %> <% end %> <% if local_assigns[:is_autocomplete] %> <%= tag.div(class: class_names("autocomplete-select-with-clear" => local_assigns[:show_all_values])) do %> <%= select %> <% end %> <% if local_assigns[:show_all_values] %> <% end %> <%= javascript_tag nonce: true do -%> window.callAutocompleteWhenReady("<%= local_assigns[:id] %>", {showAllValues: "<%= local_assigns[:show_all_values] %>"}); <% end -%> <% else %> <%= select %> <% end %> <% end %>