Form

All you need to build a form.

This is help text under the form field.
value
value
value

HTML

<form action="/" class="form">

	<fieldset class="form__fieldset">
		<label for="text" class="form__label">Input, text</label>
		<input type="text" id="text" class="form__input" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="error" class="form__label">Input, error</label>
		<input type="text" id="error" class="form__input form__input--error" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="full" class="form__label">Input, full width</label>
		<input type="text" id="full" class="form__input form__input--full" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="email" class="form__label">Input, email</label>
		<input type="email" id="email" class="form__input" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="tel" class="form__label">Input, telephone</label>
		<input type="tel" id="tel" class="form__input" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="url" class="form__label">Input, URL</label>
		<input type="url" id="url" class="form__input" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="date" class="form__label">Input, date</label>
		<input type="date" id="date" class="form__input" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="time" class="form__label">Input, time</label>
		<input type="time" id="time" class="form__input" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="datetime" class="form__label">Input, date and time</label>
		<input type="datetime-local" id="datetime" class="form__input" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="placeholder" class="form__label">Input with placeholder</label>
		<input type="url" id="placeholder" class="form__input" placeholder="Placeholder text" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="value" class="form__label">Input with value</label>
		<input type="text" id="value" class="form__input" value="Value text" />
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="note" class="form__label">Input with note</label>
		<input type="text" id="note" class="form__input" />
		<small class="form__note">This is help text under the form field.</small>
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="filter" class="form__label">Input with filter</label>
		<div class="l-relative">
			<input type="text" id="filter" class="form__input js-filter" placeholder="Start typing..." />
		</div>
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="select" class="form__label">Select</label>
		<select id="select" class="form__select">
			<option>Select option</option>
			<option selected>Select option selected</option>
			<option disabled>Select option disabled</option>
		</select>
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="select-full" class="form__label">Select, full width</label>
		<select id="select-full" class="form__select form__select--full">
			<option>Select option</option>
			<option selected>Select option selected</option>
			<option disabled>Select option disabled</option>
		</select>
	</fieldset>

	<!-- Add legend here -->
	<fieldset class="form__fieldset">
		<label for="radio" class="form__label">Radio</label>
		<ul>
			<li><label><input type="radio" name="radio" /> Radio option</label></li>
			<li><label><input type="radio" name="radio" checked/> Radio option, checked</label></li>
			<li><label><input type="radio" name="radio" disabled/> Radio option, disabled</label></li>
		</ul>
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="checkbox" class="form__label">Checkbox</label>
		<ul>
			<li><label><input type="checkbox" class="checkbox" /> Checkbox option</label></li>
			<li><label><input type="checkbox" class="checkbox" checked/> Checkbox option, checked</label></li>
			<li><label><input type="checkbox" class="checkbox" disabled/> Checkbox option, disabled</label></li>
		</ul>
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="textarea" class="form__label">Textarea</label>
		<textarea id="textarea" class="form__textarea"></textarea>
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="textarea-full" class="form__label">Textarea, full width</label>
		<textarea id="textarea-full" class="form__textarea form__textarea--full"></textarea>
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="range" class="form__label">Range</label>
		<span class="form__range js-form__range">
			<input type="range" id="range" min="1" max="100" value="50" class="form__range__slider js-form__range__slider" />
			<strong><span class="js-form__range__value"></span> value</strong>
		</span>
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="range" class="form__label">Range with steps</label>
		<span class="form__range js-form__range">
			<input type="range" id="range" min="1" max="5" value="1" step="0.1" class="form__range__slider js-form__range__slider" />
			<strong><span class="js-form__range__value"></span> value</strong>
		</span>
	</fieldset>

	<fieldset class="form__fieldset">
		<label for="range" class="form__label">Range, negative to positive</label>
		<span class="form__range js-form__range">
			<input type="range" id="range" min="-100" max="100" value="0" class="form__range__slider js-form__range__slider" />
			<strong><span class="js-form__range__value"></span> value</strong>
		</span>
	</fieldset>

	<fieldset class="form__fieldset">
		<input type="submit" value="Submit button" class="form__submit" />
		<input type="submit" value="Submit button, full width" class="form__submit form__submit--full" />
	</fieldset>
</form>

SCSS

// Form
.form {

	// Note
	&__note {
		display: block;
		margin-top: $baseline / 2;
	}

	// Fieldset
	&__fieldset {
		margin: 0 $grid-gutter $grid-gutter 0;

		@include break(medium) {
			margin: 0 ($grid-gutter / 2) ($grid-gutter / 2) 0;
		}
	}

	// Label
	&__label {
		display: block;
		font-weight: bold;
		color: $color-text;
		margin-bottom: $baseline;
		cursor: pointer;
	}

	// Input
	&__input {
		display: inline-block;
		height: $baseline * 5;
		padding: 0 $baseline;
		color: $color-text;
		border: 1px solid $color-border;
		font-family: inherit;
		font-weight: inherit;
		font-size: inherit;
		line-height: inherit;
		@include no-appearance;
		@include radius(0);
		@include antialiased;
		
		&::-webkit-inner-spin-button,
		&::-webkit-outer-spin-button {
			@include no-appearance;
		    margin: 0;
		}
		
		&:focus {
			outline: none;
			color: $color-text;
			border-color: $color-link;
		}

		// Search button
		&__search {
			width: $baseline * 2;
			height: $baseline * 2;
			display: block;
			text-align: center;
			
			@include font-size(20);
			@include line-height(20);
			@include radius(100%);
			@extend .icon-search;
			position: absolute;
			top: 0;
			right: $baseline / 2;
			z-index: 100000000000;
		}

		// Reset button
		&__reset {
			width: $baseline * 2;
			height: $baseline * 2;
			display: block;
			text-align: center;
			
			@include font-size(20);
			@include line-height(20);
			@include radius(100%);
			@extend .icon-reset;
			position: absolute;
			top: 0;
			right: $baseline / 2;
			z-index: 100000000000;
			

			&:hover {
				color: $color-text;
				text-decoration: none;
			}
		}

		// Input modifiers
		&--full {
			width: 100%;
			margin-right: 0;
		}

		&--error {
			border-color: $color-error;
		}

	}

	&__select {
		height: $baseline * 5;
		display: block;
		padding: 0 $baseline * 3 0 $baseline;
		margin: 0 $baseline $baseline * 2 0;
		background: url(../graphics/png/select.png) no-repeat right top;
		background: none, #FFF url(../graphics/svg/select.svg) no-repeat right top;
		color: $color-text;
		border: 1px solid $color-border;
		font-size: inherit;
		line-height: inherit;
		font-family: inherit;
		font-weight: inherit;
		cursor: pointer;
		
		@include no-appearance;

		&:-moz-focusring {
		    color: transparent;
		    text-shadow: 0 0 0 #000;
		}

		&:focus {
			outline: none;
			color: $color-text;
			border-color: $color-link;
		}

		// Select modifiers
		&--full {
			width: 100%;
		}
	}

	// Textarea
	&__textarea {
		@extend .form__input;
		display: block;
		padding: $baseline !important;
		min-height: $baseline * 10;

		// Textarea modifiers
		&--full {
			width: 100%;
		}
	}

	// Radiobutton
	&__radio {
		display: none;
		
		@include lt(IE9) {
			display: block;
		}
		
		+ .form__radio__label-helper {
			cursor: pointer;
			background-color: #FFF;
			border: 3px solid $color-border;
			padding: $baseline;
			display: inline-block;
			position: relative;
			top: $baseline * 0.75;
			margin-right: $baseline / 2;
			z-index: 10;
			@include radius(100%);
			
			@include lt(IE9) {
				display: none;
			}
		}
		
		&:checked {
		
			+ .form__radio__label-helper {
				border: 3px solid $color-link;
				color: $color-link;
				
				&:before {
					width: $baseline;
					height: $baseline;
					position: absolute;				
					top: $baseline / 2;
					left: $baseline / 2;
					content: ' ';
					display: block;
					background: $color-link;
					@include radius(100%);
				}
			}
		}

		&__label {
			cursor: pointer;
			white-space: nowrap;
			display: inline-block;
			position: relative;
			z-index: 100;
			padding: 0 0 $baseline 0;
			margin: 0;
		}
	}


	&__radio-group {
		list-style: none;
		margin-bottom: $baseline * 2;

		&__item {
			position: relative;
			list-style: none;
			float: left;
			margin-right: $baseline * 2;

			&:last-child {
				margin-right: 0
			}
		}
	}

	// Range
	&__range {
		display: block;
		height: $baseline * 3.5;
		margin-bottom: $baseline * 2;
	}

	input[type="range"] {
		height: 2px;
		background-color: $color-link;
		margin-bottom: $baseline * 2;
		@include no-appearance;

		&::-webkit-slider-thumb {
			width: $baseline * 2;
			height: $baseline * 2;
			background-color: $color-link;
			cursor: pointer;
			@include no-appearance;
			@include radius(100%);

			@include break(medium) {
				width: $baseline * 2.5;
				height: $baseline * 2.5;
			}
		}
	}

	// Submit
	&__submit {
		@extend .button;
		font-size: inherit;
		line-height: inherit;
		font-family: inherit;
		font-weight: inherit;

		// Submit modifiers
		&--full {
			width: 100%;
		}
	}
}

JS

// Select input value on select
$('input').click(function() {
	$(this).select();
});

// Range value
$('.js-form__range').each(function() {

    var sliderValue = $(this).find('.js-form__range__value');

    $(this).find('.js-form__range__slider').change(function(){
        sliderValue.html(this.value);
    });

    $(this).find('.js-form__range__slider').change();
});

// Input with filter
$(document).ready(function() {
	// Add search icon
	$('.js-filter').after('');

	// Add reset button
	$('.js-filter').after('');
	$('.js-form__input__reset').hide();

	$('.js-filter').keyup(function() {
		if ($.trim(this.value).length) {
			$('.js-form__input__search').hide();
			$('.js-form__input__reset').show();
		} else {
			$('.js-form__input__reset').hide();
			$('.js-form__input__search').show();
		}
	})
});

// Reset button function
$(document).on('click', '.js-form__input__reset', function() { 
	$(this).prev('.form__input').val('').keyup().select();
});