From 6847d27509ab58ab0aa24e45b3b9e71ff8fb70b7 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Wed, 3 Sep 2008 15:41:12 -0700 Subject: [PATCH] Form#serializeElements should not serialize file inputs. --- CHANGELOG | 2 ++ src/form.js | 2 +- test/unit/fixtures/form.html | 4 ++++ test/unit/form_test.js | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 60c8b56..d332c1d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Form#serializeElements should not serialize file inputs. (kangax, Lonesome Boy) + * Fix an issue with calling Event.pointer before the DOM is loaded. (kangax, jddalton) [#4 state:resolved] * Element#down on an input element should not raise error. (humeniuc, kangax) diff --git a/src/form.js b/src/form.js index 0fd2ef3..bb42428 100644 --- a/src/form.js +++ b/src/form.js @@ -12,7 +12,7 @@ var Form = { var data = elements.inject({ }, function(result, element) { if (!element.disabled && element.name) { key = element.name; value = $(element).getValue(); - if (value != null && (element.type != 'submit' || (!submitted && + if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted && submit !== false && (!submit || key == submit) && (submitted = true)))) { if (key in result) { // a key is already present; construct an array of values diff --git a/test/unit/fixtures/form.html b/test/unit/fixtures/form.html index 2259395..9ac9a0f 100644 --- a/test/unit/fixtures/form.html +++ b/test/unit/fixtures/form.html @@ -79,6 +79,10 @@ +
+ +
+
diff --git a/test/unit/form_test.js b/test/unit/form_test.js index ff4b5c9..1c12373 100644 --- a/test/unit/form_test.js +++ b/test/unit/form_test.js @@ -271,7 +271,9 @@ new Test.Unit.Runner({ $('form').serialize({ submit: false })); this.assertHashEqual({ val1:4, action:'blah' }, $('form').serialize({ submit: 'inexistent' })); - + + // file input should not be serialized + this.assertEqual('', $('form_with_file_input').serialize()); }, testFormMethodsOnExtendedElements: function() {