Class: Primer::Alpha::MultiInput

Inherits:
Component
  • Object
show all
Includes:
Forms::Dsl::InputMethods
Defined in:
app/components/primer/alpha/multi_input.rb

Overview

Multi inputs are comprised of multiple constituent fields, only one of which is visible at a given time. They are designed for situations where constituent inputs are shown or hidden based on the value of another field. For example, consider an address form. If the user chooses the USA as the country, the region input should show a list of states and US territories; if the user instead chooses Canada, the region input should show a list of Canadian provinces, etc.

Unlike everywhere else in Primer forms, constituent inputs are not directly passed a ‘name` attribute. Instead, developers pass a `name` attribute to the multi input itself. The multi input then automatically assigns each constituent input the same name. This is done so that the multi input looks like a single field from the server’s point of view. Using the address form example from earlier, this means only one value - either a US state or a Canadian provice - will be submitted to the server under the ‘region` key.

Actually, that’s not quite true. Constituent inputs are given a ‘name`, but it’s added to the input as the ‘data-name` attribute as a way to identify constituent inputs, and will not be sent to the server.

Constant Summary

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

Methods included from Forms::Dsl::InputMethods

#action_menu, #auto_complete, #button, #check_box, #check_box_group, #fields_for, #hidden, #inputs, #multi, #radio_button_group, #select_list, #separator, #submit, #text_area, #text_field

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from Primer::AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initializeObject



# File 'app/components/primer/alpha/multi_input.rb', line 43