-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
PostStatus: Prevent form submission from refreshing the page #69526
PostStatus: Prevent form submission from refreshing the page #69526
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @SainathPoojary!
This was great in most cases, but I noticed that submitting from the password field doesn't work when the Status is set to "Scheduled" and the date picker is displayed.
Screencast
CleanShot.2025-03-12.at.18.27.44.mp4
Hey @Mamaduka, I’ve moved the logic to 2025-03-13.15-33-24.mp4 |
The form provides Moving logic to |
Hey @Mamaduka, I tried to find the root cause and discovered that this issue occurs because the onSubmit event, triggered by pressing Enter, only works when there is a single input field. However, when there are multiple input fields, it doesn’t trigger the onSubmit event. Below is a demonstration using simple HTML 2025-03-14.13-32-53.mp4An alternative approach on triggering onSubmit would be to trigger onSubmit when Enter is pressed on the Password TextControl. <form
onSubmit={ ( event ) => {
event.preventDefault();
onClose();
} }
>
<TextControl
...
onKeyDown={(event) => {
if (event.key === "Enter") {
event.preventDefault();
event.target.form.dispatchEvent(
new CustomEvent("submit", {
bubbles: true,
cancelable: true,
})
);
}
}}
/>; Please Let me know your thoughts. |
Excellent detective work, @SainathPoojary! In that case, I think going with the first approach (a4f23f9) makes more sense. Why?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the follow-ups, @SainathPoojary!
Closes: #69524
What?
Fixes an issue where enabling password protection and entering a password in the “Status & Visibility” popover caused an unintended form submission, leading to a page refresh.
Why?
When pressing Enter in the password input field, the browser attempted to submit the form, refreshing the page. Since the “Save Draft” and “Publish” buttons remain disabled unless there is content in the post (title or content)
How?
• Prevents default form submission behavior to stop the page from refreshing.
Testing Instructions
• The page does not refresh.
• The popover closes as expected.
• The “Save Draft” button remains disabled if no content exists.
• Use Keyboard shortcut to save the post
Screenshots or screencast
Before:
2025-03-11.14-46-43.mp4
After:
2025-03-11.14-50-10.mp4