Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/form on submit content type #11615

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

EthanShao
Copy link

Version Number

7.51.0

Codesandbox

request body and onSubmit issue on Form

Reproduce steps

  1. Access Codesandbox

  2. Set Form enctype to application/x-www-form-urlencoded, application/json or text/plain

  3. open browser developer tools and swtich the tab to network

  4. submit form and check post callhttps://httpbin.org/post?encType=xxx

    application/x-www-form-urlencoded
    Actual: wrong body format formData
    Expect: url encodes e.g. username=u1&password=encrypt+password

    application/json
    Actual: formJsonString couldn't update in onSubmit
    Expect: body could be updated in onSubmit

    text/plain
    Actual: wrong body format formData
    Expect: string body format e.g. username:u1\npassword:encrypt p1

Bug fixed

  1. Added enctype fn to build body. Return the correct format according to commonly enctype
  2. Removed formData, formDataJson in onSubmit. The consumer hard to distinguish which data should be updated in this mutation fn.

Other proposals

  1. The onSubmit(non-mutation fn) returned data as the body data. or add a new props Fn(non-mutation) to prepare data on Form.
const onSubmit({ data, event }) => {
  const newData = nonmutation(data)
  return newData
}
  1. Remove control._names.mount in form. Current codes only allow mount fields to be submitted. As a consumer, I want a flexible way of organizing data that prevents the introduction of hidden or read-only fields.

Copy link

codesandbox bot commented Mar 10, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

stale bot commented Apr 22, 2024

Thank you for your contributions! This Pull Request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Best, RHF Team ❤️

@stale stale bot added the stale label Apr 22, 2024
@stale stale bot removed the stale label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants