Form Input
Basic text input form fields with 'floating' labels
Sage Component
SageFormInput
<fieldset class="sage-type">
<h3 class="t-sage-heading-6">Text (default)</h3>
<%= sage_component SageFormInput, {
id: "form__fname1",
input_type: "text",
label_text: "First name",
placeholder: "First name",
required: true,
disabled: false,
has_error: false,
name: "custom_input_name",
message_text: "This is a message",
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Text (with error)</h3>
<%= sage_component SageFormInput, {
id: "form__fname2",
input_type: "text",
label_text: "First name",
placeholder: "First name",
required: true,
disabled: false,
has_error: true,
message_text: "This is a message",
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Text (prefilled)</h3>
<%= sage_component SageFormInput, {
id: "form__country1",
input_type: "text",
label_text: "Country",
placeholder: "Country",
value: "USA",
required: true,
disabled: false,
has_error: false,
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Text (prefilled) with hidden label</h3>
<%= sage_component SageFormInput, {
id: "form__country2",
input_type: "text",
label_text: "Country",
placeholder: "Country",
value: "USA",
required: true,
disabled: false,
has_error: false,
has_placeholder: false,
hide_label: true
} %>
<h3 class="t-sage-heading-6">Text (disabled)</h3>
<%= sage_component SageFormInput, {
id: "form__apt",
input_type: "text",
label_text: "PO Box",
placeholder: "PO Box",
required: true,
disabled: true,
has_error: false,
message_text: "This is a message",
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Text (readonly)</h3>
<%= sage_component SageFormInput, {
id: "form__readonly",
value: "This text can't be modified by the user",
input_type: "text",
label_text: "Can't touch this",
placeholder: "Can't touch this",
required: false,
disabled: false,
readonly: true,
has_error: false,
message_text: "This is a message",
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Email</h3>
<%= sage_component SageFormInput, {
id: "form__email",
input_type: "email",
label_text: "Email address",
placeholder: "Email address",
required: true,
disabled: false,
has_error: false,
message_text: "This is a message",
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Password</h3>
<%= sage_component SageFormInput, {
id: "form__pw",
input_type: "password",
label_text: "Create a password",
placeholder: "Create a password",
required: true,
disabled: false,
minlength: "8",
maxlength: "128",
has_error: false,
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Numbers</h3>
<%= sage_component SageFormInput, {
id: "form__num1",
input_type: "number",
label_text: "Enter quantity (max 48)",
placeholder: "Enter quantity (max 48)",
required: true,
disabled: false,
input_mode: "numeric",
pattern: "[0-9]{2}",
max: "48",
maxlength: "2",
has_error: false,
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Numbers (incremented)</h3>
<%= sage_component SageFormInput, {
id: "form__num2",
input_type: "number",
label_text: "Enter percentage (max 5%)",
placeholder: "Enter percentage (max 5%)",
required: true,
disabled: false,
input_mode: "numeric",
max: "5",
maxlength: "2",
min: "0",
step: "0.5",
has_error: false,
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Prefixed</h3>
<%= sage_component SageFormInput, {
id: "form__pre",
input_type: "text",
label_text: "Custom domain",
placeholder: "Custom domain",
required: true,
disabled: false,
input_mode: "text",
pattern: "[a-z]+\.[a-zA-Z0-9\/\-]+",
has_error: false,
prefix: "https://",
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Suffixed</h3>
<%= sage_component SageFormInput, {
id: "form__suf",
input_type: "number",
label_text: "Price per month",
placeholder: "Price per month",
required: true,
disabled: false,
input_mode: "numeric",
pattern: "[0-9]{6}",
max: "100000",
maxlength: "6",
has_error: false,
suffix: ".00",
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">Custom placeholder & label visible</h3>
<%= sage_component SageFormInput, {
id: "form__reply1",
input_type: "text",
label_text: "Reply-to email",
placeholder: "Custom placeholder text",
required: true,
disabled: false,
has_error: false,
has_placeholder: true
} %>
<h3 class="t-sage-heading-6">With Static Icon</h3>
<%= sage_component SageFormInput, {
icon: "info-circle",
id: "form__fname3",
input_type: "text",
label_text: "First name",
placeholder: "First name",
required: true,
disabled: false,
has_error: false,
name: "custom_input_name",
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">With Static Icon with Error</h3>
<%= sage_component SageFormInput, {
icon: "info-circle",
id: "form__fname4",
input_type: "text",
label_text: "First name",
placeholder: "First name",
required: true,
disabled: false,
has_error: true,
name: "custom_input_name",
message_text: "This is a message",
has_placeholder: false
} %>
<h3 class="t-sage-heading-6">With Popover</h3>
<%= sage_component SageFormInput, {
id: "form__fname5",
input_type: "text",
label_text: "First name",
placeholder: "First name",
required: true,
disabled: false,
has_error: false,
name: "custom_input_name",
has_placeholder: false
} do %>
<%= content_for :sage_form_input_popover do %>
<%= sage_component SagePopover, {
icon: "info-circle",
link: {
href: "#",
name: "Learn more about a thing",
},
popover_position: "left",
trigger_value: "Open Menu",
trigger_icon_only: true,
} do %>
<p>I can put whatever content I want in here and use the custom class as a hook to style it like a good 'ol BEM mixin!</p>
<% end %>
<% end %>
<% end %>
</fieldset>
Property | Description | Type | Default |
---|---|---|---|
|
Enables the browser to autofill values from saved fields or password managers. Refer to the allowed values for acceptable properties. |
String |
|
|
Enabling this property adds the |
Boolean |
|
|
Enabling this property adds the |
Boolean |
|
|
Enabling this property adds the |
Boolean |
|
|
Adds a static icon for visual context. See Icons under "Foundations." |
String |
|
|
Unique identifier for this input field. Should match the |
String |
|
|
Hints at the type of data to be entered. Primarily intended for mobile devices, this can influence the type of control displayed, for example a numeric input keypad instead of a standard text keyboard. |
String |
|
|
Sets the |
String |
|
|
Sets the label text for the component. |
String |
|
|
Sets the maximum numerical value for a form field. |
String |
|
|
Sets the maximum character length for a form field. |
String |
|
|
Sets the message text for the component. |
String |
|
|
Sets the minimum value for a numeric form field (ex. |
String |
|
|
Sets the minimum character length for a form field. |
String |
|
|
Unique identifier for this component. Defaults to the value provided for |
String |
|
|
Specifies a form field's validation pattern using regex. Ignored with |
String |
|
|
Inserts content to be displayed inside a default (empty) field. |
String |
|
|
Sets prefix text to be prepended to the component. |
String |
|
|
Adding this attribute allows basic HTML form validation on this field. |
String |
|
|
Enabling this property adds the |
Boolean |
|
|
Adding this attribute allows basic HTML form validation on this field. |
Boolean |
|
|
When applied to a numeric ( |
String |
|
|
Sets suffix text to be appended to the component. |
String |
|
|
Sets the value for the component. |
String |
|
Sections |
|
||
|
Provides the HTML content for the popover component, rendered at the right end of the form input. |
Restricted to Popover |
- Use of text inputs without a corresponding label is possible, but not recommended
- Ensure that the label element follows the input in the HTML in order to properly apply the "floating label" effect
- Use unique
id
andname
values for each field - Match the placeholder and label text precisely, or the "floating label" effect may appear jarring
- Take advantage of HTML client-side validation for basic fields – baked-in with most browsers
- Placeholders are not intended for detailed instructions—make use of adjacent text instead
- Do not rely on HTML client-side validation when complex and/or secure requirements are involved, such as password validation and generation
title
attributes are discouraged for use in input fields, as they are not consistently accessible for assistive technology users.