Skip to content
On this page

Time zone select

Time zone select allows a user to filter through a list of default time zones and select one or multiple values.

Usage

erb
<%= render(Impulse::TimeZoneSelectComponent.new(:user, :time_zone)) %>

Arguments

Positional arguments

NameDefaultDescription
object_nameN/AThe name of the object.
method_nameN/AThe name of the method.
priority_zonesnilA list of time zones that will be listed above the rest of the (long) list.

Keyword arguments

NameDefaultDescription
selectednilThe value of the option that you want to force select.
defaultnilThe value of the option that you want to select if the selected is nil.
modelActiveSupport::TimeZoneA list of time zones that should respond to all and return an array of objects that represent time zones; each object must respond to name and to_s. If a Regexp is given, it will attempt to match the zones using the match? method.
priority_zones_title"Prioritized time zones"The title of the group of time zones that have been prioritized.
sizemdThe size of the select control. One of sm, md, or lg.
namenilThe name of the field. By default rails will automatically create a name string based on the object_name and method_name.
input_idnilThe id of the input field.
placeholdernilThe placeholder text that is displayed within the input field.
include_hiddentrueSee the "Gotcha" section of rails select tag.
disabledfalseDisables the select control.
requiredfalseMakes the select control a required field.
multiplefalseWhether multiple values can be selected or not.
clearabletrueWhether the clear button should be shown or not.

Examples

Prioritizing zones

You can also supply an array of ActiveSupport::TimeZone, ActiveSupport::TimeZone.us_zones for a list of US time zones, ActiveSupport::TimeZone.country_zones(country_code) for another country’s time zones or a Regexp to select the zones of your choice.

erb
<%= render(Impulse::TimeZoneSelectComponent.new(:user, :time_zone, ActiveSupport::TimeZone.us_zones)) %>
<%= render(Impulse::TimeZoneSelectComponent.new(:user, :time_zone, [ActiveSupport::TimeZone["Alaska"], ActiveSupport::TimeZone["Hawaii"]])) %>
<%= render(Impulse::TimeZoneSelectComponent.new(:user, :time_zone, /Australia/)) %>
<%= render(Impulse::TimeZoneSelectComponent.new(:user, :time_zone, ActiveSupport::TimeZone.all.sort)) %>

Custom blankslate

A blankslate is displayed when the input's text does not match any of the options.

erb
<%= render(Impulse::TimeZoneSelectComponent.new(:user, :time_zone)) do |c| %>
  <% c.with_blankslate { "We could not find that time zone in our directory!" } %>
<% end %>

Integrating with form_with

Wrap your time_zone_select tag with the impulse_form_with method. The f.time_zone_select tag accepts the same arguments.

erb
<%= impulse_form_with model: @user do |f| %>
  <%= f.select :time_zone %>
<% end %>

<%= impulse_form_with model: @user do |f| %>
  <%= f.select :time_zone, ActiveSupport::TimeZone.us_zones %>
<% end %>

<%= impulse_form_with model: @user do |f| %>
  <%= f.select :time_zone, nil, default: "Hawaii" %>
<% end %>

<%= impulse_form_with model: @user do |f| %>
  <%= f.select :time_zone do |c| %>
    <% c.with_blankslate { "Time zone not found!" } %>
  <% end %>
<% end %>

Slots

with_blankslate

Overwrite the default blankslate message by passing a custom block.

NameDefaultDescription
system_args{}HTML attributes that should be passed to the Rails' content_tag method.

Imports

js
import '@ambiki/impulse-view-components/dist/elements/autocomplete';
scss
@import '~@ambiki/impulse-view-components/dist/elements/autocomplete';

JS API

Read here.

Released under the MIT License.