Termination with validation
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/additional-methods.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.js"></script>
<div data-role="page" data-control-title="Terminate" id="pageTerminate" class="events">
<div data-theme="a" data-role="header">
<h3>Terminate</h3>
</div>
<div data-role="content">
<form id="formEvent_terminate" action="">
<div data-role="fieldcontain" data-controltype="textinput" class="pcbid_selections">
<label for="pcbid_terminate">PCBID</label>
<input name="pcbid_terminate" id="pcbid_terminate" class="pcbid_selections" placeholder="" value="" type="text" data-mini="true">
</div>
<div data-role="fieldcontain" data-controltype="textarea">
<label for="input_reason_terminate">Reason</label>
<input name="input_reason_terminate" id="input_reason_terminate" placeholder="Enter a reason for this PCBID's termination." data-mini="true">
</div>
<div data-role="fieldcontain" data-controltype="textarea">
<label for="notes_terminate">Notes</label>
<textarea name="notes_terminate" id="notes_terminate" placeholder="Enter notes regarding this termination event." data-mini="true"></textarea>
</div>
<input type="submit" data-inline="true" data-icon="arrow-l" data-iconpos="left" value="Back" class="back">
<input type="submit" data-inline="true" data-icon="plus" data-iconpos="left" value="Submit">
<input type="submit" data-inline="true" data-icon="delete" data-iconpos="left" value="Clear">
</form>
</div>
</div>
JavaScript
//global variables, need to change how this is done.
var pcbClientEvent, pcbidPointer, notesPointer, eventObject;
//predefine the username to avoid trying to figure out if it's null or undefined later on.
sessionStorage.setItem('user', 'winlogon');
//jquery validator initialization
$.validator.setDefaults({
debug: true,
success: "valid"
});
//extra code to validate the checkboxes in the repairReview form.
//Adapted from: http://stackoverflow.com/questions/15375027/jquery-validate-error-container-not-disappearing-after-custom-method-has-success
$.validator.addMethod("repairReviewRule", function (value, element) {
return ($('#checkbox_repaired_repairReview').is(':checked') || $('#checkbox_ihError_repairReview').is(':checked') || $('#checkbox_esdSuspected_repairReview').is(':checked') || $('#checkbox_ohOther_repairReview').is(':checked'));
}, "Please indicate the result of the repair.");
//extra code to force only letters, although it could be used with any regex passed in at the rule level, used for capturing winlogon below.
//adapted from: http://stackoverflow.com/questions/2476378/jquery-validate-plugin-accept-letters-only
$.validator.addMethod("accept", function (value, element, param) {
return value.match(new RegExp("^" + param + "$"));
});
//end extra code
function createPCBIDObject() {
pcbClientEvent.eventType.common.user = sessionStorage.user === "" ? null : sessionStorage.user;//theoretically this should never return null
//this should always return an int, validation prevents anything but digits from being submitted.
pcbClientEvent.eventType.common.pcbid = $('#' + pcbidPointer).val() === "" ? null : parseInt($('#' + pcbidPointer).val(), 10);//the 10 forces parseInt to process as base 10.
pcbClientEvent.eventType.common.notes = $('#' + notesPointer).val() === "" ? null : $('#' + notesPointer).val();
pcbClientEvent.eventType.assign.sbePN = $("#input_assign_sbePN").val() === "" ? null : $("#input_assign_sbePN").val();
...