I am using jquery validator http://validation.bassistance.de/documentation/ and although it is working and validating the form, I have a requirement where I need to create a custom event so when a field is validated, I can hide that field from view.
For example, in my form I have a field 'dept'. The idea, is that when it passes validation, is to hide the field so the user can move on to the next one. The reason that I want to do this is one of space.
I have read the docs and searched google but cannot find an answer, so hence my request here. I have pasted my code and if anyone could offer any advice, I would be grateful.
jquery code
$(function ()
{
$.validator.setDefaults(
{
errorClass: 'form_error_frmreport',
errorElement: 'div'
});
$("#frmreport").validate(
{
rules:
{
email:
{
required: true,
email: true
},
position:
{
required: true
},
feedback:
{
required: true
}
},
messages:
{
email:
{
required: "<br />* required: You must enter a valid email address"
},
position:
{
required: "<br />* required: Please state your position"
},
feedback:
{
required: "<br />* required: Please enter as much information regarding the exact nature of the problem"
}
},
submitHandler: function() {
if ($("#frmreport").valid() === true) {
var data = $("#frmreport").serialize();
$.post('/sample/admin/frm10010.php', data, function(msg) {
var messageOutput = '';
for (var i = 0; i<msg.length; i++){
messageOutput += msg[i].box+' ';
}
$("#confirm_department").hide();
var $dialog = $('<div id="dialog"></div>')
.html('Your report was successfully submitted and a representative will respond to you shortly.<br /><br />Thank you.');
$dialog.dialog({
autoOpen: true,
modal: true,
title: 'Report submission successfull',
width: 400,
height: 200,
draggable: false,
resizable: false,
buttons: {
Close: function() {
$( this ).dialog( "close" );
}
}
});
$("#frmreport").get(0).reset();
}, 'json');
} else
{
return;
}
},
success: function() {
//validator.resetForm();
//$.html("You have entered a box");
//$("#BA_boxform").get(0).reset();
}
});
});
html form
<div id="formShow">
<form id="frmreport" method="post">
<fieldset>
<legend><span class="subtitle">Submit Technical Report</span></legend>
<div class="spacer"></div>
<label for="dept">Department</label><br />
<input id="dept" name="dept" class="text" type="text" /><br />
<label for="name">Full Name:</label><br />
<input id="name" name="name" class="text" type="text" /><br />
<label for="email">Email address:</label><br />
<input id="email" name="email" class="text" type="text" /><br />
<label for="position">Position:</label><br />
<input id="position" name="position" class="text" type="text" /><br />
<label for="feedback">Problem:</label><br />
<textarea name="feedback" cols="22" rows="5"></textarea><br />
</fieldset><br />
<input class="submit" type="submit" name="submit" value="Submit Report" />
<input class="cancel" type="reset" name="cancel" value="Clear Report" />
</form>
</div>