- return a;
- }
- return $(el).val();
-};
-
-/**
- * Clears the form data. Takes the following actions on the form's input fields:
- * - input text fields will have their 'value' property set to the empty string
- * - select elements will have their 'selectedIndex' property set to -1
- * - checkbox and radio inputs will have their 'checked' property set to false
- * - inputs of type submit, button, reset, and hidden will *not* be effected
- * - button elements will *not* be effected
- */
-$.fn.clearForm = function(includeHidden) {
- return this.each(function() {
- $('input,select,textarea', this).clearFields(includeHidden);
- });
-};
-
-/**
- * Clears the selected form elements.
- */
-$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
- var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
- return this.each(function() {
- var t = this.type, tag = this.tagName.toLowerCase();
- if (re.test(t) || tag == 'textarea' || (includeHidden && /hidden/.test(t)) ) {
- this.value = '';
+
+ return $(el).val().replace(rCRLF, '\r\n');
+ };
+
+ /**
+ * Clears the form data. Takes the following actions on the form's input fields:
+ * - input text fields will have their 'value' property set to the empty string
+ * - select elements will have their 'selectedIndex' property set to -1
+ * - checkbox and radio inputs will have their 'checked' property set to false
+ * - inputs of type submit, button, reset, and hidden will *not* be effected
+ * - button elements will *not* be effected
+ */
+ $.fn.clearForm = function(includeHidden) {
+ return this.each(function() {
+ $('input,select,textarea', this).clearFields(includeHidden);
+ });
+ };
+
+ /**
+ * Clears the selected form elements.
+ */
+ $.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
+ var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
+
+ return this.each(function() {
+ var t = this.type, tag = this.tagName.toLowerCase();
+
+ if (re.test(t) || tag === 'textarea') {
+ this.value = '';
+
+ } else if (t === 'checkbox' || t === 'radio') {
+ this.checked = false;
+
+ } else if (tag === 'select') {
+ this.selectedIndex = -1;
+
+ } else if (t === 'file') {
+ if (/MSIE/.test(navigator.userAgent)) {
+ $(this).replaceWith($(this).clone(true));
+ } else {
+ $(this).val('');
+ }
+
+ } else if (includeHidden) {
+ // includeHidden can be the value true, or it can be a selector string
+ // indicating a special test; for example:
+ // $('#myForm').clearForm('.special:hidden')
+ // the above would clean hidden inputs that have the class of 'special'
+ if ((includeHidden === true && /hidden/.test(t)) ||
+ (typeof includeHidden === 'string' && $(this).is(includeHidden))) {
+ this.value = '';
+ }
+ }
+ });
+ };
+
+
+ /**
+ * Resets the form data or individual elements. Takes the following actions
+ * on the selected tags:
+ * - all fields within form elements will be reset to their original value
+ * - input / textarea / select fields will be reset to their original value
+ * - option / optgroup fields (for multi-selects) will defaulted individually
+ * - non-multiple options will find the right select to default
+ * - label elements will be searched against its 'for' attribute
+ * - all others will be searched for appropriate children to default
+ */
+ $.fn.resetForm = function() {
+ return this.each(function() {
+ var el = $(this);
+ var tag = this.tagName.toLowerCase();
+
+ switch (tag) {
+ case 'input':
+ this.checked = this.defaultChecked;
+ // fall through
+
+ case 'textarea':
+ this.value = this.defaultValue;
+
+ return true;
+
+ case 'option':
+ case 'optgroup':
+ var select = el.parents('select');
+
+ if (select.length && select[0].multiple) {
+ if (tag === 'option') {
+ this.selected = this.defaultSelected;
+ } else {
+ el.find('option').resetForm();
+ }
+ } else {
+ select.resetForm();
+ }
+
+ return true;
+
+ case 'select':
+ el.find('option').each(function(i) { // eslint-disable-line consistent-return
+ this.selected = this.defaultSelected;
+ if (this.defaultSelected && !el[0].multiple) {
+ el[0].selectedIndex = i;
+
+ return false;
+ }
+ });
+
+ return true;
+
+ case 'label':
+ var forEl = $(el.attr('for'));
+ var list = el.find('input,select,textarea');
+
+ if (forEl[0]) {
+ list.unshift(forEl[0]);
+ }
+
+ list.resetForm();
+
+ return true;
+
+ case 'form':
+ // guard against an input with the name of 'reset'
+ // note that IE reports the reset function as an 'object'
+ if (typeof this.reset === 'function' || (typeof this.reset === 'object' && !this.reset.nodeType)) {
+ this.reset();
+ }
+
+ return true;
+
+ default:
+ el.find('form,input,label,select,textarea').resetForm();
+
+ return true;
+ }
+ });
+ };
+
+ /**
+ * Enables or disables any matching elements.
+ */
+ $.fn.enable = function(b) {
+ if (typeof b === 'undefined') {
+ b = true;