x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!-- Required Field -->
<input type="text" name="required_field" id="required_field" placeholder="Full name (required)" required="required" class="input" />
<div class="invalid-feedback text-sm text-negative mbs-1">can't be blank</div>
<!-- Min Length Field -->
<input type="text" name="min_length_field" id="min_length_field" placeholder="Full name (min: 3 chars)" required="required" minlength="3" class="input" />
<div class="invalid-feedback text-sm text-negative mbs-1">is too short (minimum is 3 character)</div>
<!-- Max Length Field -->
<input type="text" name="max_length_field" id="max_length_field" placeholder="Full name (max: 10 chars)" maxlength="10" class="input" />
<div class="invalid-feedback text-sm text-negative mbs-1">is too long (maximum is 10 character)</div>
<!-- Min Field -->
<input type="number" name="min_field_field" id="min_field_field" placeholder="Age (min: 18)" min="18" class="input" />
<div class="invalid-feedback text-sm text-negative mbs-1">must be greater than or equal to 18</div>
<!-- Max Field -->
<input type="number" name="max_field" id="max_field" placeholder="Age (max: 16)" min="0" max="16" class="input" />
<div class="invalid-feedback text-sm text-negative mbs-1">must be less than or equal to 16</div>
<!-- Phone Field -->
<input type="tel" name="phone_field" id="phone_field" placeholder="+1234567890" pattern="^\+\d{1,15}$" maxlength="16" class="input" />
<div class="invalid-feedback text-sm text-negative mbs-1">is invalid</div>
<!-- Url Field -->
<input type="url" name="url_field" id="url_field" placeholder="https://example.com" pattern="https?://.+" maxlength="2048" class="input" />
<div class="invalid-feedback text-sm text-negative mbs-1">is invalid</div>
<!-- Pattern Field -->
<input type="text" name="pattern_field" id="pattern_field" placeholder="000.000.000-00" pattern="\d{3}\.\d{3}\.\d{3}-\d{2}" maxlength="14" class="input" />
<div class="invalid-feedback text-sm text-negative mbs-1">is invalid</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<%# Required Field %>
<%= text_field_tag "required_field", nil, placeholder: "Full name (required)", required: true, class: "input" %>
<div class="invalid-feedback text-sm text-negative mbs-1">can't be blank</div>
<%# Min Length Field %>
<%= text_field_tag "min_length_field", nil, placeholder: "Full name (min: 3 chars)", required: true, minlength: 3, class: "input" %>
<div class="invalid-feedback text-sm text-negative mbs-1">is too short (minimum is 3 character)</div>
<%# Max Length Field %>
<%= text_field_tag "max_length_field", nil, placeholder: "Full name (max: 10 chars)", maxlength: 10, class: "input" %>
<div class="invalid-feedback text-sm text-negative mbs-1">is too long (maximum is 10 character)</div>
<%# Min Field %>
<%= number_field_tag "min_field_field", nil, placeholder: "Age (min: 18)", min: 18, class: "input" %>
<div class="invalid-feedback text-sm text-negative mbs-1">must be greater than or equal to 18</div>
<%# Max Field %>
<%= number_field_tag "max_field", nil, placeholder: "Age (max: 16)", min: 0, max: 16, class: "input" %>
<div class="invalid-feedback text-sm text-negative mbs-1">must be less than or equal to 16</div>
<%# Phone Field %>
<%= phone_field_tag "phone_field", nil, placeholder: "+1234567890", pattern: '^\+\d{1,15}$', maxlength: "16", class: "input" %>
<div class="invalid-feedback text-sm text-negative mbs-1">is invalid</div>
<%# Url Field %>
<%= url_field_tag "url_field", nil, placeholder: "https://example.com", pattern: 'https?://.+', maxlength: "2048", class: "input" %>
<div class="invalid-feedback text-sm text-negative mbs-1">is invalid</div>
<%# Pattern Field %>
<%= text_field_tag "pattern_field", nil, placeholder: "000.000.000-00", pattern: '\d{3}\.\d{3}\.\d{3}-\d{2}', maxlength: "14", class: "input" %>
<div class="invalid-feedback text-sm text-negative mbs-1">is invalid</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
.input {
appearance: none;
background-color: var(--input-background, var(--color-bg));
border: 1px solid var(--input-border-color, var(--color-border));
border-radius: var(--input-radius, var(--rounded-md));
box-shadow: var(--input-box-shadow, var(--shadow-xs));
font-size: var(--input-font-size, var(--text-sm));
inline-size: var(--input-inline-size, var(--size-full));
min-block-size: var(--input-block-size, var(--size-9));
padding: var(--input-padding, .375rem .75rem);
&:is(textarea[rows=auto]) {
field-sizing: content;
max-block-size: calc(.875rem + var(--input-max-rows, 10lh));
min-block-size: calc(.875rem + var(--input-rows, 2lh));
}
&:is(select):not([multiple], [size]) {
background-image: url("select-arrow.svg");
background-position: center right var(--size-2);
background-repeat: no-repeat;
background-size: var(--size-4) auto;
}
&::file-selector-button {
font-weight: var(--font-medium);
}
&:user-invalid {
border-color: var(--color-negative);
}
&:user-invalid ~ .invalid-feedback {
display: flex;
}
&:disabled {
cursor: not-allowed; opacity: var(--opacity-50);
}
}
.input--actor {
input {
border: 0; inline-size: 100%; outline: 0;
}
img:not([class]) {
filter: var(--input-icon-color, var(--color-filter-text));
}
&:focus-within {
outline: var(--input-outline-size, 2px) solid var(--color-selected-dark);
}
}
:is(.checkbox, .radio) {
accent-color: var(--color-primary); transform: scale(1.2);
}
.range {
accent-color: var(--color-primary);
}
/* Hide invalid-feedback element */
.invalid-feedback {
display: none;
}
/* Styles shared between components */
:is(.input, .checkbox, .radio, .range) {
&:focus-visible {
outline: var(--input-outline-size, 2px) solid var(--color-selected-dark);
}
.field_with_errors & {
border-color: var(--color-negative);
}
}
Java Script is not required or multiple files are needed, check the notes.