Be sure to use an appropriate type attribute on all inputs (e.g., email for email address or number for numerical information) to take advantage of newer input controls like email verification, number selection, and more.
Disabled
Add the disabled boolean attribute on an input to prevent user interactions and make it appear lighter.
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.
<divclassName="form-group has-success">
<labelfor="inputSuccess1">
has-success
<svgclassName="lexicon-icon lexicon-icon-asterisk reference-mark"focusable="false"role="presentation"
>
<usehref="/icons.svg#asterisk" />
</svg>
</label>
<inputclassName="form-control"id="inputSuccess1"type="text" />
<divclassName="form-feedback-group">
<divclassName="form-feedback-item">This is a form-feedback-item.</div>
<divclassName="form-feedback-item">
<spanclassName="form-feedback-indicator">
<svgclassName="lexicon-icon lexicon-icon-check-circle-full"focusable="false"role="presentation"
>
<usehref="/icons.svg#check-circle-full" />
</svg>
</span>
This is a form-feedback-indicator.
</div>
<divclassName="form-text">This is form-text.</div>
</div>
</div>
Warning
This is a form-feedback-item.
This is a form-feedback-indicator.
This is form-text.
Snippet
<divclassName="form-group has-warning">
<labelfor="inputWarning1">
has-warning
<svgclassName="lexicon-icon lexicon-icon-asterisk reference-mark"focusable="false"role="presentation"
>
<usehref="/icons.svg#asterisk" />
</svg>
</label>
<inputclassName="form-control"id="inputWarning1"type="text" />
<divclassName="form-feedback-group">
<divclassName="form-feedback-item">This is a form-feedback-item.</div>
<divclassName="form-feedback-item">
<spanclassName="form-feedback-indicator">
<svgclassName="lexicon-icon lexicon-icon-warning-full"focusable="false"role="presentation"
>
<usehref="/icons.svg#warning-full" />
</svg>
</span>
This is a form-feedback-indicator.
</div>
<divclassName="form-text">This is form-text.</div>
</div>
</div>
Error
This is a form-feedback-item.
This is a form-feedback-indicator.
This is form-text.
Snippet
<divclassName="form-group has-error">
<labelfor="inputError1">
has-error
<svgclassName="lexicon-icon lexicon-icon-asterisk reference-mark"focusable="false"role="presentation"
>
<usehref="/icons.svg#asterisk" />
</svg>
</label>
<inputaria-describedby="input-error-1-error-message"aria-invalid="true"className="form-control"id="inputError1"type="text"
/>
<divclassName="form-feedback-group">
<divclassName="form-feedback-item"id="input-error-1-error-message">
This is a form-feedback-item.
</div>
<divclassName="form-feedback-item">
<spanclassName="form-feedback-indicator">
<svgclassName="lexicon-icon lexicon-icon-exclamation-full"focusable="false"role="presentation"
>
<usehref="/icons.svg#exclamation-full" />
</svg>
</span>
This is a form-feedback-indicator.
</div>
<divclassName="form-text">This is form-text.</div>
</div>
</div>
HTML 5 Validations
The browser default form validation. Submit the form to see it in action.
Novalidate Attribute
The novalidate attribute on the form element will disable the browser’s default validation tooltip. This allows us to display custom validation text while taking advantage of the browser’s built in form validation API.
You will need to prevent form submission if there are invalid fields by using the HTMLInputElement.checkValidity() method.
Snippet
document.addEventListener('submit', function (event) {
vart=event.target;
if (t.getAttribute('novalidate') ==='') {
if (t.checkValidity() ===false) {
event.preventDefault();
event.stopPropagation();
}
t.classList.add('was-validated');
}
});
The was-validated class on the form element displays the success or error messages for :valid and :invalid fields. It should be added when the form is submitted. Documentation on HTML5 form validation attributes can be found on MDN.