JSFiddle - React, Tailwind, and code Playground
by Taleeb Anwar
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="container">
<form>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
<br />
<br />
<br />
<br />
<label for="firstName">First Name*</label>
<!-- COMMENT THIS LINE OUT AFTER YOU HOVER OVER LINK--><a title='errorTitle' data-toggle='popover' class='invalidIconAndErrorMsg' data-trigger='hover' data-placement='top' data-content='Required Field Can Not Be Left Blank'>Error!</a>
<div class="grpWrapper">
<div class="input-group form-group"> <span class="input-group-addon color">
<i class="fa fa-user fa-2x fa-fw color-icon1"></i>
</span>
<input type="text" id="firstName" name="firstName" size="30" maxlength="30" placeholder="First Name..." />
</div>
</div>
</div>
</div>
</form>
</div>
JavaScript
$('[data-toggle="popover"]').popover();
function getLabel(el) {
return $("label[for=" + $(el).attr("id") + "]");
}
function insertInvalidIconAndErrorMsg(label, errorTitle, errorMsg) {
$("<a title='" + errorTitle + "' data-toggle='popover' class='invalidIconAndErrorMsg' data-trigger='hover' data-placement='top' data-content='" + errorMsg + "'>Error!</a>").insertAfter($(label));
$('[data-toggle="popover"]').off('popover').popover();
}
function validateInputText(el) {
var label = getLabel(el);
if ($(el).val().trim().length <= 0) {
insertInvalidIconAndErrorMsg(label, "Required Field", "Required Field Can not Be Left Blank.");
}
}
$(":input").on('blur', (function () {
validateInputText(this);
}));