The select_tag
helper tag generates a dropdown menu.
- name: The input's name attribute.
- label: Adds label text above the dropdown menu.
- options:
- Format 1: An array of options.
["Red", "Blue", "Yellow"]
- Format 2: An array of arrays, containing option Text and Value.
[["Red", "crimson"], ["Blue", "azure"], ["Yellow", "gold"]]
- Format 1: An array of options.
- include_blank: Whether or not to include a blank option at the start to allow the dropdown to be empty.
- value: The selected option value.
- id: The input's ID attribute. By default this will be set to the name, converted into a
variable_name
-style string.
Helper Tag
{% select_tag name: "name", label: "Dropdown menu label!", options: [["Red", "crimson"], ["Blue", "azure"], ["Yellow", "gold"]], include_blank: true, value: "crimson", id: "id" %}
HTML Output
<label for="id" class="d-block">Dropdown menu label!</label>
<select class="custom-select" id="id" name="name">
<option value=""></option>
<option value="crimson" selected>Red</option>
<option value="azure">Blue</option>
<option value="gold">Gold</option>
</select>