MultiInput
MultiInput component is part of the Primer ViewComponents forms framework. If you are building a form, please consider using the framework instead of this standalone component.Description
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.
Arguments
| Name | Default | Description |
|---|---|---|
name | StringValue for the HTML name attribute. | |
id | StringValue for the HTML id attribute. | |
class | StringCSS classes to include in the input's HTML | |
classes | ArrayCSS classes to include in the input's HTML | |
caption | StringA string describing the field and what sorts of input it expects. Displayed below the input. | |
label | StringLabel text displayed above the input. | |
visually_hide_label | BooleanWhen set to | |
disabled | BooleanWhen set to | |
hidden | BooleanWhen set to | |
invalid | BooleanIf set to | |
validation_message | StringA string displayed between the caption and the input indicating the input's contents are invalid. This option is, by default, set to the first Rails validation message for the input (assuming the form is associated with a model object). Use | |
label_arguments | HashAttributes that will be passed to Rails' | |
scope_name_to_model | BooleanDefault | |
scope_id_to_model | BooleanDefault | |
required | BooleanDefault | |
aria | HashKey/value pairs that represent Aria attributes and their values. Eg. | |
data | HashKey/value pairs that represent data attributes and their values. Eg. | |
system_arguments | HashA hash of attributes passed to the underlying Rails builder methods. These options may mean something special depending on the type of input, otherwise they are emitted as HTML attributes. See the Rails documentation for more information. In addition, the usual Primer utility arguments are accepted in system arguments. For example, passing |