Repair with validation refactor
by delliottg
HTML
<link rel="stylesheet" href="http://jquery.bassistance.de/validate/demo/css/screen.css">
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/additional-methods.js"></script>
<div id="divRepair" class="rightside padsidestwenty events">
<h2>Repair Event Form</h2>
<div class='rightside padsidestwenty'>
<form id="formEvent_repair" action="">
<div data-role="fieldcontain" data-controltype="textinput" class="eventType" style="display: none;">
<label for="eventType_repair"></label>
<input name="eventType_repair" id="eventType_repair" placeholder="" value="Repair" type="hidden">
</div>
<div data-role="fieldcontain" data-controltype="textinput" class="pcbid_selections" tabindex="1">
<label for="pcbid_repair">PCBID *</label>
<input name="pcbid_repair" id="pcbid_repair" class="pcbid_selections" placeholder="52759" value="" type="text" data-mini="true" />
</div>
<div id="repair_department" data-role="fieldcontain" data-controltype="selectmenu">
<label for="select_reporting_department">Reported By: *</label>
<select id="select_reporting_department" data-native-menu="false" name="select_reporting_department" data-mini="true">
<option value="">Select Department</option>
<option value="Calibration">Calibration</option>
<option value="Electronic Assembly">Electronic Assembly</option>
<option value="Electronic Test">Electronic Test</option>
<option value="Final_Test">Final Test</option>
<option value="Production">Production</option>
<option value="Service">Service</option>
</select>
</div>
<div data-role="fieldcontain"...
JavaScript
var sbeGlobal = {
pcbClientEvent: null,
pcbidPointer: null,
pcbidUpperPointer: null,
notesPointer: null,
eventObject: null,
eventTypePointer: null,
assemblyDrawingPointer: null,
//sbeGlobal.doesPCBIDExist is a boolean determined in the function call to doesPCBIDExist() below.
doesPCBIDExist: false,
//similarly, sbeGlobal.shouldPCBIDexist is used to determine whether a given pcbid should exist or not.
//It's set in the pageshow events or their Submit events
shouldPCBIDExist: false,
repairReporter: null,
repairStatus: null,
repairCategory: null,
repairReason: null,
repairInput: null
};
jQuery.validator.addMethod('selectCheck', function (value) {
//console.log("Inside custom select validator\nValue: " + value);
return (value !== '');
}, "Please choose a reason for the repair.");
//extra bit of selector level validation for the repair page so when the user selects a repair reason the validation is run
$("select[name^='select_repair_']").change(function () {
$(this).valid();
});
$("#select_reporting_department").change(function () {
$("#select_reporting_department").valid();
});
$(document).ready(function () {
$("#formEvent_repair").validate({
submitHandler: function (form, event) {
/*
console.log(form);
console.log(event);
console.log($(this));
console.log($("#pcbid_repair").val());
console.log($("#select_reporting_department option:selected").val());
console.log($('input[name=rdo_repair_status]:checked', '#formEvent_repair').val());
console.log($('input[name=rdo_repair_category]:checked', '#formEvent_repair').val());
console.log(sbeGlobal.repairReason);
*/
sbeGlobal.repairReporter = $("#select_reporting_department option:selected").val();
sbeGlobal.repairStatus = $('input[name=rdo_repair_status]:checked', '#formEvent_repair').val();
sbeGlobal.repairCategory = sbeGlobal.repairStatus == "Set...