Skip to content

Releases

4.6.1

Choose a tag to compare

@kevindb kevindb released this 28 Nov 20:32
302dc93

A fix release for the files in the package. No API change. jQuery 1.7.2 or later is still supported.

Fixes

  • src/jquery.form.js is the classic build again, as in 4.3.0. In 4.3.0 that file was the package's main and its only unminified classic build, so projects copy it, concatenate it or //= require it by path. 4.4.0 replaced it with the ES module source (import jQuery from "jquery"), so a <script> tag rejected it and ajaxForm() and ajaxSubmit() were undefined. The 4.4.0 notes did not say so. It is now a copy of dist/jquery.form.js, in the npm package and in the git tag that Bower, Composer and jsDelivr's /gh/ URLs install from. main (dist/jquery.form.js) and module (dist/jquery.form.mjs) are unchanged, so require, import and bundlers load the same files as in 4.6.0.
  • cdnjs serves the classic build at jquery.form.js again. cdnjs copies both dist/ and src/ from the git tag into one folder, so https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.6.0/jquery.form.js is the ES module source. In 4.6.1 the two files are identical. jquery.form.min.js, the file the docs link, was correct in every version.

Packaging

  • A bundler that imports jquery-form/src/jquery.form.js gets the classic build, as with 4.3.0. webpack runs its AMD branch and registers the plugin; esbuild and Vite treat it as CommonJS and get the (root, jQuery) factory without running it. Import jquery-form instead, which loads dist/jquery.form.mjs, as it has since 4.4.0.
  • The ES module sources moved to src/esm/ in the repository and are no longer in the npm package. Nothing pointed at them: module is the built dist/jquery.form.mjs. If you imported a file under src/ other than jquery.form.js, import jquery-form instead.

Testing

  • CI now runs the suite and the end-to-end tests on jQuery 1.7.2, 1.12.4, 3.7.1, 4.0.0 and 4.1.0, in Chromium, Firefox and WebKit.
  • New tests pin patterns that Drupal, Backdrop, Plone, Concrete CMS, OpenSourcePOS and Review Board rely on: a submit button set on form.clk, extraData added in beforeSend, controls changed in beforeSerialize, ajaxSubmit(fn), formToArray(true) as $.ajax data, and the module build sharing the page's jQuery.

Full changelog: v4.6.0...v4.6.1

5.0.0-beta.1

5.0.0-beta.1 Pre-release
Pre-release

Choose a tag to compare

@kevindb kevindb released this 27 Nov 03:56

5.0 is a major release with breaking changes. Read the migration guide before upgrading: each change below links to its entry, with who is affected and before and after code. With $.fn.ajaxSubmit.debug = true, the latest 4.x logs a warning for most of the features 5.0 removes. 4.x stays available (npm install jquery-form@4) and gets security fixes on a best-effort basis, with no set end date; see the security policy.

Install the beta

npm i jquery-form@next

jquery is now a peer dependency, so install it too if your project does not list it: npm i jquery@^3.7.1 jquery-form@next. The beta is on the next dist-tag; npm i jquery-form still installs 4.x. Please report problems on #629 or in a new issue. The pull request is #646.

Highlights

  • Sends what a native submission sends. Fields follow tree order, only buttons, inputs, selects and textareas are sent, and image buttons, dirname, _charset_ and empty file inputs follow the HTML spec. The guide's "What your server receives" table shows each request body before and after.
  • A smaller, modern plugin. jQuery 3.5+ only, current browsers only, ES2020 syntax with no transpile; the jQuery < 3, Internet Explorer, Opera Presto and EdgeHTML code is gone. The minified build is 23.8 kB (9.1 kB gzip), down from 26.5 kB (10.1 kB gzip) in 4.6.0.
  • An exports map. Node import gets the module build, bundlers get it for import and require, and require in Node keeps the CommonJS factory.
  • Selector options are only selectors. A string in target, iframeTarget or includeHidden is never parsed as HTML, so it can't create elements.

Breaking changes

Platform

Packaging

Removals

Behavior and serialization

Kept on purpose (see Differences from a native submission): a selected file makes the request multipart without enctype, a GET request keeps the action's query, and a clicked submit input without a value sends an empty value.

The iframe transport: tell us if you use it

5.0 keeps the hidden-iframe upload transport, but only when you pass iframe: true; every other upload uses FormData. It may be removed in 6.0. If you use iframe: true, comment on #629 with your use case.

Docs

  • A new migration guide, in the docs site menu as "Upgrading to 5.0" and linked from the README, with a "New in 5.0" section.
  • The API page documents every method, including formToArray, enable, selected and $.fieldValue, and lists what 5.0 removes.
  • The options page documents includeHidden, the iframe rejection arguments that differ from $.ajax, and the deliberate differences from a native submission.
  • The examples are rewritten for 5.0, with no demo server and with server snippets that escape their output. The Form Fields page shows what fieldValue and fieldSerialize return, and the FAQ is rewritten.
  • SECURITY.md supports 5.x, with 4.x fixes on a best-effort basis.

Testing (no effect on the published files)

  • The suite runs on Chromium, WebKit and Firefox with jQuery 3.5.0, 3.7.1 and 4.0.0 (1112 tests per jQuery version), at 100% coverage.
  • The serialization oracle and the end-to-end tests compare with a native submission; the differences from a native submission that 5.0 removes are no longer allowed in them.
  • Published-file tests check each exports key, Node import resolving to the module build, the module condition, and that a deep src import fails.
  • Every breaking change has a test that fails on 4.6.0 and an entry in the migration guide.
  • The package is published from CI with npm provenance; pre-releases go to the next dist-tag.

4.6.0

Choose a tag to compare

@kevindb kevindb released this 26 Nov 21:11
a94d7c1

Warning

src/jquery.form.js is an ES module in this release, not the classic build it was in 4.3.0. It also imports the other files in src/. A page or build that copies it by path and loads it as a classic script fails, and ajaxForm() and ajaxSubmit() are undefined. require("jquery-form"), import "jquery-form" and bundlers aren't affected. Update to 4.6.1, which ships the classic build at that path again, or copy dist/jquery.form.js instead. The same applies to cdnjs: https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.6.0/jquery.form.js serves this ES module, because cdnjs copies src/jquery.form.js over the classic build. Use jquery.form.min.js, which is correct, or 4.6.1.

A bug-fix release. No breaking changes are intended. Behavior changes only where the old behavior was a bug or differed from a native form submission, so read the list below if your code relied on any of them. jQuery 1.7.2 or later is still supported. Every change is tested on jQuery 1.7.2, 3.7.1 and 4.0.0, and the test suite now runs on Chromium, Firefox and WebKit.

Fixes

  • target and iframeTarget strings are looked up only as selectors. Both were passed to $(), which builds elements from a string that looks like HTML and runs any inline handlers in it. A string is now looked up with $(document).find(). A selector finds the same elements as before. A string that starts with < matches nothing (and logs a message when $.fn.ajaxSubmit.debug is on). On jQuery 1.7.2, a selector with a tag in an attribute value, such as div[title="<b>"], now works. Elements and jQuery objects are used as given.
  • A lone surrogate is sent as U+FFFD. formSerialize, fieldSerialize, ajaxSubmit and iframe uploads threw URIError when a field name or value, or a key or string value in data or extraData, held an unpaired UTF-16 surrogate. Each one is now replaced with U+FFFD, as a native form submission and FormData do. A string data option is passed through unchanged.
  • Spaces encode as + on every jQuery version. On jQuery 3 and later, formSerialize, fieldSerialize, GET query strings and urlencoded bodies wrote a space as %20, while jQuery 1 and 2 and a native form submission write +. They now write + everywhere. Servers decode both the same way; only code that compares the strings sees a difference.
  • An iframe response that cannot be parsed rejects with parsererror, as error and complete already reported. When the response also carries an error status (a status attribute outside 2xx), error, ajaxError and the rejection receive its statusText, as $.ajax reports a server error.
  • An iframe upload no longer sends a clicked button that a disabled <fieldset> disables, as the other transports and a native submission already did.

Packaging

  • Bundlers get the module build. The browser field pointed at the minified classic build, so webpack, Vite and Browserify bundled it. It is removed: webpack and Vite use module (dist/jquery.form.mjs) and Browserify uses main (dist/jquery.form.js). New jsdelivr and unpkg fields keep a bare CDN URL serving dist/jquery.form.min.js.
  • The CommonJS factory uses the window it is given. require("jquery-form")(root, $) read the global window and document, so it threw in Node without a global DOM. It now takes them from root.
  • LICENSE-MIT is in the package, next to LICENSE. The license field is now the SPDX expression (LGPL-2.1-or-later OR MIT): the same terms, written the current way.
  • The package homepage is the docs site, https://jquery-form.github.io/form/.

Deprecations

  • Replacing $.fieldValue to change what is serialized logs a deprecation warning once per page when $.fn.ajaxSubmit.debug is on. It still works in 4.x; 5.0 drops it, so use jQuery valHooks instead.
  • The API docs now have a Deprecations section listing every warning and its replacement.

Docs

  • The README is now a short landing page: installation, usage (module import, CommonJS, script tag), file uploads, compatibility and security. The full reference is on the docs site.
  • The docs site's links to old malsup.com pages point at its own pages, and its demos load over https.
  • Bug reports use an issue form that asks for the plugin, jQuery and browser versions. Security reports go through SECURITY.md.

Full changelog: v4.5.0...v4.6.0

4.5.0

Choose a tag to compare

@kevindb kevindb released this 10 Nov 23:41
4e4a73c

Warning

src/jquery.form.js is an ES module in this release, not the classic build it was in 4.3.0. It also imports the other files in src/ now. A page or build that copies it by path and loads it as a classic script fails, and ajaxForm() and ajaxSubmit() are undefined. require("jquery-form"), import "jquery-form" and bundlers aren't affected. Fixed in 4.6.1; on this release, copy dist/jquery.form.js instead.

The plugin's source is now split into modules, and this release fixes a long list of bugs found while pinning down its behavior. No breaking changes are intended. Behavior changes only where the old behavior was a bug or differed from a native form submission, so read the lists below if your code relied on any of them. jQuery 1.7.2 or later is still supported. Every change is tested on jQuery 1.7.2, 3.7.1 and 4.0.0.

New

  • delegation: "<selector>" limits ajaxForm delegation to forms that match a selector (#353). delegation: true is unchanged, but it now logs a warning on jQuery 3 and later, where it binds every form on the page.
  • ajaxFormUnbind() also removes delegated bindings, and ajaxFormUnbind(selector) removes one of them.
  • requestFormat: "json" sends the form as a JSON body (#545). The idea came from #557 by @zhangciwu.
  • error and complete accept arrays of functions, as in $.ajax.
  • ajaxSubmit on jQuery's slim build throws a clear error (#541) instead of failing later.

Deprecations

These log a warning once per page when $.fn.ajaxSubmit.debug is on, and 5.0 will remove them.

  • clearInputs: use clearFields. $.fn.attr2: use .prop() or .attr().
  • ajaxForm on an empty selection before the DOM is ready, which queues the binding: call it inside $(fn), or use delegation: "<selector>".
  • The iframe transport chosen automatically when the browser has no FormData: set iframe: true.
  • The closeKeepAlive option, a workaround for Safari 3 and 4.
  • jQuery older than 3.5. 5.0 will need jQuery 3.5 or later.

enable and selected are kept.

Fixes: submission and transports

  • Every transport uses the same request method. method wins over type, and it is read after beforeSubmit.
  • A url of false or "" submits to the form's action.
  • A string data option is treated as a query string.
  • this in callbacks is the caller's context object, not a copy of it.
  • success runs when target matches nothing.
  • beforeSend returning false cancels a FormData upload, as it already did on the other transports.
  • uploadProgress keeps a custom xhr factory, and reports position 0 and 0% for a progress event with nothing loaded.
  • A multipart enctype is recognized regardless of case and surrounding spaces.
  • File uploads with GET put file names in the URL, never [object File].

Fixes: iframe uploads

  • Events fire in the same order as $.ajax, and a beforeSend veto ends the global events with ajaxStop.
  • Every upload settles exactly once, including when an exception is thrown. abort() before the delayed post cancels it.
  • Uploads started in the same millisecond use different frames, and an iframeTarget without a name receives the upload.
  • dataType is read case-insensitively.
  • A frame that is not in the document fails with an error instead of opening a new window.
  • The form's attributes are restored exactly after the upload (#380).
  • With closeKeepAlive, controls disabled in beforeSubmit are posted and re-enabled afterwards.

Fixes: serialization, fields and form members

  • Controls named like form members (getAttribute, ownerDocument, tagName, reset, clk and others) no longer break the plugin. A control named parentNode throws a clear error.
  • The contents of a disabled <fieldset> or <optgroup> are not sent. semantic: true sends only controls the form owns. Named fieldset, output and object elements are not sent. A lone CR in a value is sent as CRLF on every jQuery version.
  • ajaxForm sends the browser's SubmitEvent.submitter when no click was captured, for example after pressing Enter or calling requestSubmit(button).
  • resetForm matches a native reset. It keeps the values of checkboxes, radios, hidden inputs and buttons, empties file inputs instead of throwing, and selects the last default option of a single select.
  • clearForm and clearFields clear datetime-local inputs.

Docs

  • How to sanitize a response inserted by target, with dataFilter (jQuery 3.5 and later).
  • The list of options that must come only from trusted code, not from user input.
  • What an iframe upload response has to look like.

Build

  • The classic build runs its whole factory in strict mode. The same three dist files are published.

Known, not changed in 4.5.0

  • String values of target and iframeTarget are still passed to $(), so pass only selectors from your own code (see the trusted options list). 4.6.0 will look them up only as selectors.

Full changelog: v4.4.0...v4.5.0

4.4.0

Choose a tag to compare

@kevindb kevindb released this 07 Nov 03:15
a06a0c8

Warning

Changed in this release and not listed below: src/jquery.form.js is an ES module. In 4.3.0 it was the classic build and the package's main. Here it starts with import jQuery from "jquery", so a page or build that loads it as a classic script fails with Cannot use import statement outside a module, and ajaxForm() and ajaxSubmit() are undefined. require("jquery-form"), import "jquery-form" and bundlers aren't affected, because they go through main and module. Fixed in 4.6.1, which ships the classic build at that path again. On 4.4.0, copy dist/jquery.form.js instead.

The first release since 4.3.0 (2020). It fixes four cross-site scripting vulnerabilities, adds jQuery 4 support and a module build, and fixes several long-standing bugs. There is no API change; the changes below are the ones a page could notice. Upgrading is recommended for everyone.

Security

All four affect 4.3.0 and earlier, and are fixed in 4.4.0. CVE IDs have been requested and will be added to the advisories when assigned.

Advisory Severity Affected feature
GHSA-x8mc-9vpg-2rc8 Medium The iframe upload transport (iframe: true) built HTML from field names, the clicked button's name, the csrf-param meta tag and iframeSrc
GHSA-8395-7m7x-q7q2 Medium resetForm() passed a <label>'s for attribute to $()
GHSA-g7mw-rwc2-4h3g Medium semantic: true built a selector from the form's id
GHSA-4w39-46xw-8jm2 Medium target inserted a parsed JSON response as HTML

Thanks to Rudloff for reporting the iframe transport and resetForm() issues. The other two were found in a maintainer security review.

Hardening in the same area:

  • The Rails CSRF token (<meta name="csrf-token">) is added only to same-origin iframe uploads, and only when they post the form. A cross-origin upload no longer receives it, and a GET upload no longer puts it in the query string.
  • An extra field named hasOwnProperty no longer breaks iframe uploads.

jQuery 4 and packaging

  • jQuery 4 is supported (#616). Every change is tested on jQuery 1.7.2, 3.7.1 and 4.0.0.
  • A module build. module points at dist/jquery.form.mjs, which registers the plugin when imported, so bundlers such as Vite pick it up (#618). main moved from src/jquery.form.js to dist/jquery.form.js, the classic script-tag, AMD and CommonJS build, and dist/jquery.form.min.js is still there. src/jquery.form.js is now the ES module source (see the warning above).
  • The published package is smaller. It contains dist, src, the README and the license, without the tests and repository files.
  • Published with npm provenance from GitHub Actions.
  • dist/ files no longer carry /* eslint */ or /* global */ comments, which applied to code concatenated after the plugin (#553).

Fixes and behavior changes

  • The iframe transport builds its hidden inputs and iframe with DOM APIs. Array and object data/extraData values are sent as separate fields, as $.param sends them, instead of "a,b" or [object Object] (#597).
  • resetForm() on a <label> resets the control its for attribute names. This never worked before: a plain id matched nothing, and a match threw.
  • semantic: true matches form="…" controls by comparing the attribute, so a form id with quotes or brackets no longer throws or picks up unrelated fields.
  • target inserts only string responses. If jQuery has parsed the response (JSON or XML), the target is left unchanged, a message is logged under debug, and success is still called.
  • A <button> without a type attribute is captured as the submitter (#588), so its name and value are sent, as in a native submit.
  • resetForm, clearFields, fieldValue and selected accept nodes without a tag name (#600). resetForm on the document resets the fields inside it.
  • JSON responses are parsed with JSON.parse only. JSON that only eval accepted (single quotes, unquoted keys) now fails with a parse error instead of being evaluated.
  • Iframe uploads with dataType: "script" run the response, as $.ajax does.
  • Aborting an iframe upload rejects its Deferred with "aborted", fires ajaxComplete and ajaxStop, and removes the iframe. A second abort, or an abort after completion, does nothing.
  • Iframe responses that fail to parse report parsererror instead of success with no data.
  • FormData uploads serialize data with the global $.ajaxSettings.traditional, and data: {} no longer adds a field with an empty name.
  • GET urls with a fragment keep the form data, placed before the fragment.
  • Controls named like form properties (elements, action, setAttribute, removeAttribute) no longer break serialization or iframe uploads.

Known, not changed in 4.4.0

  • With delegation: true on jQuery 3 and later, the handler is not scoped to the selected forms. Bind ajaxForm directly to the forms instead.
  • dataType: "script" on jQuery 4 delivers undefined to success, because jQuery 4 loads such requests through a script tag. The script still runs.

Full changelog: v4.3.0...v4.4.0

v4.3.0

Choose a tag to compare

@kevindb kevindb released this 07 Jun 04:06

Note

In this release src/jquery.form.js is the classic build and the package's main. In 4.4.0 through 4.6.0 that path holds the ES module source instead, which a <script> tag can't load. 4.6.1 restores the classic build there. If you copy this file by path, update to 4.6.1 or later, or copy dist/jquery.form.js, the classic build in every release from 4.4.0.

New Features

  1. #566 Adds beforeFormUnbind callback

Bug Fixes

  1. #572 Updates default iframeSrc to be 'about:blank' for browsers other than IE

v4.2.2

Choose a tag to compare

@kevindb kevindb released this 09 Aug 20:59

Changes

  1. 0762c5b #530 Updates license to use "LGPLv2.1 (or later) or MIT"
    Clarifies that either LGPLv2.1 (or later) or MIT license may be used.

v4.2.1

Choose a tag to compare

@kevindb kevindb released this 29 Mar 13:24

Bug Fixes

  1. 12b358a #521 Replace serialized "+" with space
    This fixes/reverts a serious regression introduced by #262
    Thanks to @MarkCarver for the fix

v4.2.0

Choose a tag to compare

@kevindb kevindb released this 19 Mar 18:47

News

jQuery Form is confirmed to be compatible with jQuery 2 and 3! 🎉
If you see any incompatibilities, please report a bug or, preferrably, a pull request.

New Features

  1. 55fba84 #486 Adds method option for API compatibility with newer versions of jQuery

Bug Fixes

  1. 8434a5f #495 Makes ajaxSubmit with 'target' option compatible with jQuery>=1.12.1

v4.1.0

Choose a tag to compare

@kevindb kevindb released this 09 Mar 17:09

New Features

  1. #436 Allows formToArray and ajaxSubmit to work on non-form tags
  2. #158 #421 #516 #517 When serializing text, encode all line breaks as CRLF pairs per the
    application/x-www-form-urlencoded specification
  3. 76a0b2a #450 #502 Updates AMD definition and adds CommonJS support
  4. Moves documentation from malsup.com to GitHub Pages
  5. Adds automated testing using ESLint, Grunt, Mocha, Chai, and PhantomJS

Bug Fixes

  1. 76c7c90 #461 Outside fields bug fix prevents fields from being doubled in non-IE browsers
  2. #518 #258 IE fix if form is in a different document
⌂ 换网址