ANSWER
jsFiddle Demo
HTML
<form action="#">
<table>
<tr>
<td>
<label for="reporte_f1">Motivo del reporte:
<br />
</label>
<textarea id="reporte_f1" rows="7" cols="50"></textarea>
</td>
</tr>
</table>
<div>
<input type="submit" class="reporta" value="Reportar" />
</div>
</form>
JS
function reportar(v_id, motivo, razon) {
$('.reporta').html('<img src=\"img/cargando2.gif\" width=\"30px\" height=\"30px\"/>');
$.ajax({
url: "forms.php?form=10",
data: {
v_id: v_id,
motivo: motivo,
razon: razon
},
type: "POST",
success: function (response) {
$(".reportar[rel]").overlay().close();
$('#dialogo').fadeIn(250);
$('#dialogo').html("<ul><li class='ack'>El reporte ha sido enviado correctamente</li></ul>");
setInterval(function () {
$('#dialogo').fadeOut(400);
}, 3000);
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Ha ocurrido un error al cargar los datos");
}
});
}
$(function () {
$('.reporta').click(function () { //.reporta is the submit field of the form
var motivo = $('#reportar select').val();
var razon = $('#reportar textarea').val();
reportar(v_id, motivo, razon); //Ajax call
});
//creation of LiveValidation object
var reporte_f1 = new LiveValidation('reporte_f1', {
validMessage: "Gracias!",
wait: 300
});
reporte_f1.add(Validate.Presence, {
failureMessage: "Por favor, introduzca algo"
});
//The regex pattern here has to be matched
reporte_f1.add(Validate.Format,
{ pattern: /^\w+$/i, failureMessage: "Por favor, introduzca un mensaje válido" } );
});
Note
I found this out by looking at the following example.
Also taken from the following example
When a LiveValidation object is instantiated, if it finds it is a child of a form, it will automatically attach itself to the submit event of the form, so when it is submitted, validation on all the LiveValidation objects inside it will be performed automatically. If any of the validations fail it will stop the form submitting (this of course only works when javascript is on in the users bowser, so be sure to do some validation on the server too!).
You can also specify the onlyOnSubmit option to be true when you create the LiveValidation object to make it only validate when the form is submitted. This is demonstrated in the following example.
Note also that the email field has no validation that it is present, therefore if this is not filled in the form will still be valid, as it will be treated as an optional field.
In this example the outcome is overidden if it is valid as this page has nowhere to submit to - instead of submitting, it will alert that it is valid, in real life it will just carry on submitting if valid.