jquery / jquery/jquery

Consider switching `serialize`/`serializeArray` to FormData

Open
#5,778 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Serialize
Dominant language
JavaScript
Stars
59.8k
Forks
20.4k
Avg merge
17h 32m
Merged PRs (30d)
4

Description

BTW, I've been thinking about using FormData here. We'd get all that filtering we're doing out of the box. There are a few issues, though:

  1. valHooks would be skipped. Now, outside of IE we now only have them for multi-select and FormData already handles multi-select identically as we do. Therefore, it's mostly about hooks defined by userland code, plugins, etc. I'm not sure how common are those, but we could re-evaluate for 5.0.
  2. FormData works nicely on forms, but .serialize() can also be called on a collection of form elements, even if they're not lying in a form. I wish we didn't do this, serialization should always happen on the form level, but we do support it. I wonder how common such usage is compared to calling .serialize() on a form, but I wouldn't be surprised if it's common.

Originally posted by @mgol in #5245

To add to the above, during the team discussion @gibson042 suggested we may still try to do a version of it in 4.x by:

  1. Adding temporary form props to individual elements so that FormData has a temporary form to work with.
  2. Applying valHooks after FormData usage by finding elements with matching names and running the valHooks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the existing serialize/serializeArray behavior and the FormData and valHooks constraints described here. Check both form collections and standalone form elements, including multi-select handling; done means a compatible approach has been established for these cases and userland hooks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.