Forms gather information from users via inputs, such as text boxes, text areas, selects, checkboxes, and radio buttons. Labels sit atop these inputs.
Overview
We are heavily based on bootstrap forms, so look there for more info. We differ in base states (hover, focus, active), handling checkboxes, radio buttons and in general we have simplified syntax and do not support all features.
Forms should not be used without a .form-group structure except in exceptional cases
Vertical forms
Create vertical forms with the grid by adding the .elastic-grid--vertical class to the form tag.
<formclass="elastic-grid--vertical">
<divclass="form-group">
<labelfor="custom-id">Date not available for festival:</label>
<inputtype="text"id="custom-id">
</div>
<divclass="form-group">
<labelfor="country">Spoken language:</label>
<divclass="flex-wrap">
<selectid="country">
<optionvalue=""selecteddisabledhidden>Select</option>
<option>Czech Republic</option>
<option>Norway</option>
<option>Poland</option>
</select>
<div>
<spanclass="tag">English <ahref=#><iclass="fal fa-search"></i></a></span>
<spanclass="tag">Czech <ahref=#><iclass="fal fa-search"></i></a></span>
</div>
</div>
</div>
<divclass="form-group">
<labelfor="time">Request for interpreter:</label>
<div>
<inputclass="form-check-input"id="checkbox-1"type="checkbox"value="value1">
<labelfor="checkbox-1"></label>
</div>
</div>
</form>
Vertical forms + Highlighted forms
When you use the vertical form you can also consider using the .form--highlighted-labels class to emphasize the labels like in the following custom forms example.
<divclass="card">
<formclass="form--highlighted-labels elastic-grid--vertical">
<divclass="form-group">
<labelfor="checkbox-10">When do you have time?</label>
<inputclass="form-check-input"id="checkbox-10"type="checkbox"value="value1">
<labelfor="checkbox-10">Monday</label>
<inputclass="form-check-input"id="checkbox-2"type="checkbox"value="value2"checked>
<labelfor="checkbox-2">Tuesday</label>
<inputclass="form-check-input"id="checkbox-3"type="checkbox"value="value3"checked>
<labelfor="checkbox-3">Wednesday</label>
<inputclass="form-check-input"id="checkbox-4"type="checkbox"value="value4"disabled>
<labelfor="checkbox-4">Thursday</label>
</div>
<divclass="form-group">
<labelfor="volunteerActivity">What do you want to do?</label>
<selectid="volunteerActivity">
<optionvalue=""selecteddisabledhidden>Select..</option>
<optionvalue="gardening">Gardening</option>
<optionvalue="babysitting">Babysitting</option>
<optionvalue="drawing">Drawing</option>
<optionvalue="running">Running</option>
</select>
</div>
<divclass="form-group">
<labelfor="exampleRadios">Can you stay for the party?</label>
<inputclass="form-check-input"type="radio"name="exampleRadios"id="iExampleRadios1"value="option1"checked>
<labelfor="iExampleRadios1">
Yes
</label>
<inputclass="form-check-input"type="radio"name="exampleRadios"id="iExampleRadios2"value="option2">
<labelfor="iExampleRadios2">
No
</label>
<aclass="link db"href="#">Reset fields</a>
</div>
<divclass="form-group">
<labelfor="exampleFormControlTextarea1"class="mt4">Upload your photo</label>
<divclass="btn-photo-group">
<buttontype="button"class="btn btn--action-outline"><iclass="fas fa-cloud-upload-alt"></i> Upload</button>
</div>
</div>
<divclass="flex-gap--right mt4">
<aclass="link"href="#"><iclass="fal fa-trash-alt"></i> Delete all values</a>
</div>
</form>
</div>
Horizontal forms
Create horizontal forms with the grid by using the elastic grid class - .elastic-grid--horizontal-12 or if you need form fields to be wider use .elastic-grid--horizontal-20.
Use to solicit a short, single line of text or a number. Use when the user must enter a name, email address, phone number, street address, etc.
<form>
<labelfor="email">Email address</label>
<inputtype="email"id="emailT"placeholder="Enter email">
<smallid="emailHelp"class="form-text muted">We'll never share your email with anyone else.</small>
</form>
Components with inline items
Use mainly in the lightboxes. Add the .form--inline class to the form tag. Use .form-group to separate input fields with labels from another input fields. Put the input and the last element into the div tag. This last element usually contains:
Only input, select or similar field.
Input, select or similar field followed by the icons. In this case, put icons in the div with the .form-group__icons class. Icons are placed in the same row.
Input, select or similar field followed by the tags. In this case, put tags in the separate div and add the .flex-wrap class. That will place the tags in the next row.
.form--inline is always used with a combination of .elastic-grid--vertical
If there are no labels listed in the form, then .form--inlinemust not be used
Forms should always be a combination of elastic-grid--vertical and .form--inline
Use to describe a form input and indicate whether the input is required or optional. Clearly written labels should eliminate the need for placeholder text in text boxes and text areas.
Placeholders
Avoid using placeholder text by making sure the label above the text box is clear. If you still need additional instructional context, consider a Tooltip next to the label header or microcopy under the label, so the helper content doesn't disappear when a user starts typing.
Form controls
Textual form controls—like inputs, select lists and textareas — are styled with in the same way. Included are styles for general appearance, focus state, sizing, and more.
To separate blocks of input use .form-group class which applies small margin to the bottom.
Help text
Block-level help text in forms can be created by using .form-text. Feel free to add .muted class to designifying the importance.
Readonly
Add the readonly boolean attribute on an input to prevent modification of the input’s value. Read-only inputs appear lighter (just like disabled inputs), but retain the standard cursor.
If you want to have elements in your form styled as plain text, use the .form-control-plaintext class to remove the default form field styling and preserve the correct margin and padding.
Checkboxes are for selecting one or several options in a list.
Disabled checkboxes and radios are supported, but to provide a not-allowed cursor on hover of the parent <label>, you’ll need to add the disabled attribute to the .form-check-input. The disabled attribute will apply a lighter color to help indicate the input’s state.
Apply basic styling by providing form-check-input class.
<divclass="form-check">
<inputclass="form-check-input"type="radio"name="exampleRadios"id="exampleRadios1"value="option1"checked>
<labelfor="exampleRadios1">
Default radio
</label>
</div>
Inline
Group radios on the same horizontal row by adding .form-check--inline to any .form-check.
<form>
<divclass="form-check form-check--inline">
<inputclass="form-check-input"type="radio"name="exampleRadios"id="iexampleRadios1"value="option1"checked>
<labelfor="iexampleRadios1">
Default radio
</label>
</div>
<divclass="form-check form-check--inline">
<inputclass="form-check-input"type="radio"name="exampleRadios"id="iexampleRadios2"value="option2">
<labelfor="iexampleRadios2">
Second default radio
</label>
</div>
</form>
Buttons and use of flex-gap--* classes
When a button or a set of buttons needs to be placed at the end of the form, use some of the flex-gap--* classes. Mostly the flex-gap--right class is being used. To read more, check out the Flexbox section.
Modals have a special style for showing buttons at their end. And since the submit action triggers an ajax POST request, they are placed outside of the form / .form-group structure.