JSFiddle - React, Tailwind, and code Playground
by matthias_h
HTML
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<form method="POST" id="TestForm">
<input name="txtIn" type="text" id="txtIn">
<br />
<input name="txtIn1" type="text" id="">
<p></p>
<button id="submit">Submit</button>
</form>
CSS
label.error:after {
content:"";
display: inline-block;
margin-left:10px;
background: url("http://dummyimage.com/15x15/de1417/de1417.png") no-repeat;
width: 15px;
height: 15px;
}
JavaScript
$('#TestForm').validate({
rules: {
txtIn: {
required: true,
rangelength: [8, 16]
}
},
messages: {
txtIn: {
required: "Please enter something",
rangelength: ""
},
errorPlacement: function (error, element) {
error.appendTo(element.next('.errormessagewrapper').children());
},
// specifying a submitHandler prevents the default submit, good for the demo
submitHandler: function () {
alert("submitted!");
},
// set this class to error-labels to indicate valid fields
success: function (label) {
},
highlight: function (element, errorClass, validClass) {
$(element).next('.errormessagewrapper').children('span').addClass("icon-cancel").removeClass("icon-checkmark");
},
unhighlight: function (element, errorClass, validClass) {
$(element).next('.errormessagewrapper').children('span').removeClass("icon-cancel").addClass("icon-checkmark");
}
}
});