From 08d7bb2de6f54fefab0556dd6cd3e802c6bf717b Mon Sep 17 00:00:00 2001 From: opurockey Date: Fri, 27 Mar 2026 23:34:19 +0600 Subject: [PATCH 1/3] Prevent dashboard quick submission if both title and content fields are empty --- src/js/_enqueues/wp/dashboard.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/js/_enqueues/wp/dashboard.js b/src/js/_enqueues/wp/dashboard.js index 5216611d5dc3c..5b4c2f3a329e7 100644 --- a/src/js/_enqueues/wp/dashboard.js +++ b/src/js/_enqueues/wp/dashboard.js @@ -145,6 +145,12 @@ jQuery( function($) { t = $('#quick-press').on( 'submit', function( e ) { e.preventDefault(); + // Don't submit if both the title and content are empty. + if ( '' === t.find('#title').val() && '' === t.find('#content').val() ) { + $('#title').trigger( 'focus' ); + return; + } + // Show a spinner. $('#dashboard_quick_press #publishing-action .spinner').show(); From 383b95b40e9c6ba5c7c64397748bfea01925b0a5 Mon Sep 17 00:00:00 2001 From: opurockey Date: Sun, 29 Mar 2026 15:13:28 +0600 Subject: [PATCH 2/3] Fixed spacing and readability --- src/js/_enqueues/wp/dashboard.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/js/_enqueues/wp/dashboard.js b/src/js/_enqueues/wp/dashboard.js index 5b4c2f3a329e7..d8299cc29478c 100644 --- a/src/js/_enqueues/wp/dashboard.js +++ b/src/js/_enqueues/wp/dashboard.js @@ -146,8 +146,11 @@ jQuery( function($) { e.preventDefault(); // Don't submit if both the title and content are empty. - if ( '' === t.find('#title').val() && '' === t.find('#content').val() ) { - $('#title').trigger( 'focus' ); + if ( + '' === t.find( '#title' ).val() && + '' === t.find( '#content' ).val() + ) { + $( '#title' ).trigger( 'focus' ); return; } From 899ed5b7f7f5a59c8487b10aec11362768bd4dd1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 29 Mar 2026 16:50:27 -0700 Subject: [PATCH 3/3] Use setCustomValidity and reportValidity --- src/js/_enqueues/wp/dashboard.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/js/_enqueues/wp/dashboard.js b/src/js/_enqueues/wp/dashboard.js index d8299cc29478c..2b87d91c8d06a 100644 --- a/src/js/_enqueues/wp/dashboard.js +++ b/src/js/_enqueues/wp/dashboard.js @@ -137,20 +137,30 @@ jQuery( function($) { * @return {void} */ window.quickPressLoad = function() { - var act = $('#quickpost-action'), t; + var act = $( '#quickpost-action' ), t = $( '#quick-press' ), titleInput, contentInput; // Enable the submit buttons. $( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false ); - t = $('#quick-press').on( 'submit', function( e ) { + titleInput = t.find( '#title' ); + contentInput = t.find( '#content' ); + + function validateAtLeastOne() { + var isFilled = titleInput.val().trim() || contentInput.val().trim(), + message = isFilled ? '' : wp.i18n.__( 'You must provide at least the title or the content.' ); + titleInput[0].setCustomValidity( message ); + contentInput[0].setCustomValidity( message ); + } + + t.on( 'input', validateAtLeastOne ); + + t.on( 'submit', function( e ) { e.preventDefault(); // Don't submit if both the title and content are empty. - if ( - '' === t.find( '#title' ).val() && - '' === t.find( '#content' ).val() - ) { - $( '#title' ).trigger( 'focus' ); + validateAtLeastOne(); + if ( ! e.target.checkValidity() ) { + e.target.reportValidity(); return; } @@ -189,7 +199,7 @@ jQuery( function($) { // Change the QuickPost action to the publish value. $('#publish').on( 'click', function() { act.val( 'post-quickpress-publish' ); } ); - $('#quick-press').on( 'click focusin', function() { + t.on( 'click focusin', function() { wpActiveEditor = 'content'; });