JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<form id="sampleForm" name="sampleForm">
<div>
<label for="body">Body:</label>
<input type="text" id="body" name="body"></input>
</div>
<div>
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject"></input>
</div>
<div>
<button id="errorButton">Submit</button>
</div>
</form>
JavaScript
$( document ).ready( function() {
$("#errorButton").click(function() {
var errorJson = '{"body": "Please enter a body.","subject": "Please enter a subject." }';
var errors, form, validator;
// Parse the JSON into an object;
errors = $.parseJSON(errorJson);
// Get the form
form = $( "#sampleForm" );
// Get the validator
validator = form.validate();
// Show the errors
validator.showErrors( errors );
return false;
});
});