Skip to content

Commit 189e675

Browse files
committed
v3.05 - allow additional fields to be cleared in clearFields and clearForm
1 parent 362cc6f commit 189e675

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

jquery.form.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* jQuery Form Plugin
3-
* version: 3.04 (03-APR-2012)
3+
* version: 3.05 (06-APR-2012)
44
* @requires jQuery v1.3.2 or later
55
*
66
* Examples and documentation at: http://malsup.com/jquery/form/
@@ -978,7 +978,7 @@ $.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
978978
var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
979979
return this.each(function() {
980980
var t = this.type, tag = this.tagName.toLowerCase();
981-
if (re.test(t) || tag == 'textarea' || (includeHidden && /hidden/.test(t)) ) {
981+
if (re.test(t) || tag == 'textarea') {
982982
this.value = '';
983983
}
984984
else if (t == 'checkbox' || t == 'radio') {
@@ -987,6 +987,15 @@ $.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
987987
else if (tag == 'select') {
988988
this.selectedIndex = -1;
989989
}
990+
else if (includeHidden) {
991+
// includeHidden can be the valud true, or it can be a selector string
992+
// indicating a special test; for example:
993+
// $('#myForm').clearForm('.special:hidden')
994+
// the above would clean hidden inputs that have the class of 'special'
995+
if ( (includeHidden === true && /hidden/.test(t)) ||
996+
(typeof includeHidden == 'string' && $(this).is(includeHidden)) )
997+
this.value = '';
998+
}
990999
});
9911000
};
9921001

0 commit comments

Comments
 (0)