2010-06-14 19:22:49 +00:00
|
|
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
|
|
|
|
|
|
var vitro;
|
2010-07-20 23:24:01 +00:00
|
|
|
|
|
|
|
// vitro == null: true
|
|
|
|
// vitro === null: false (only true if undefined)
|
|
|
|
// typeof vitro == 'undefined': true
|
|
|
|
if (!vitro) {
|
2010-06-14 19:22:49 +00:00
|
|
|
vitro = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
vitro.customFormUtils = {
|
2010-06-14 20:06:52 +00:00
|
|
|
|
|
|
|
hideForm: function() {
|
|
|
|
this.hideFields(this.form);
|
|
|
|
},
|
|
|
|
|
|
|
|
clearFormData: function() {
|
|
|
|
this.clearFields(this.form);
|
|
|
|
},
|
2010-06-14 19:22:49 +00:00
|
|
|
|
|
|
|
// This method should always be called instead of calling hide() directly on any
|
|
|
|
// element containing form fields.
|
|
|
|
hideFields: function(el) {
|
2010-09-03 19:32:34 +00:00
|
|
|
// Clear any input and error messages, so if we re-show the element it won't still be there.
|
2010-06-14 19:22:49 +00:00
|
|
|
this.clearFields(el);
|
|
|
|
el.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Clear data from form elements in element el
|
|
|
|
clearFields: function(el) {
|
2010-09-03 19:32:34 +00:00
|
|
|
el.find(':input[type!="hidden"][type!="submit"][type!="button"]').each(function() {
|
2010-09-03 20:18:36 +00:00
|
|
|
$(this).val('');
|
2010-09-03 19:32:34 +00:00
|
|
|
// Remove a validation error associated with this element.
|
|
|
|
// For now we can remove the error elements. Later we may include them in
|
|
|
|
// the markup, for customized positioning, in which case we will empty them
|
|
|
|
// but not remove them here. See findValidationErrors().
|
2011-02-21 16:09:40 +00:00
|
|
|
$('[id=' + $(this).attr('id') + '_validationError]').remove();
|
2010-09-03 19:32:34 +00:00
|
|
|
});
|
|
|
|
|
2010-06-22 22:12:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Return true iff there are validation errors on the form
|
|
|
|
findValidationErrors: function() {
|
|
|
|
|
|
|
|
return this.form.find('.validationError').length > 0;
|
|
|
|
|
|
|
|
// RY For now, we just need to look for the presence of the error elements.
|
|
|
|
// Later, however, we may generate empty error messages in the markup, for
|
|
|
|
// customized positioning, in which case we need to look for whether they have
|
|
|
|
// content. See clearFormData().
|
|
|
|
// var foundErrors = false,
|
|
|
|
// errors = this.form.find('.validationError'),
|
|
|
|
// numErrors = errors.length,
|
|
|
|
// i,
|
|
|
|
// error;
|
|
|
|
//
|
|
|
|
// for (i = 0; foundErrors == false && i < numErrors; i++) {
|
|
|
|
// error = errors[i];
|
|
|
|
// if (error.html() != '') {
|
|
|
|
// foundErrors = true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return foundErrors;
|
2010-09-02 19:54:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
capitalize: function(word) {
|
|
|
|
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
2010-07-20 23:24:01 +00:00
|
|
|
}
|
2010-06-14 19:22:49 +00:00
|
|
|
}
|