Created
October 7, 2016 04:13
-
-
Save kellenmace/f23ae82f8d6142cebcc0a6d7b710c61e to your computer and use it in GitHub Desktop.
require-checkbox-is-checked-on-wordpress-post-save.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( function ( $ ) { | |
$( document ).ready( function () { | |
// Require that one of the checkboxes is checked when publishing/updating posts | |
$( 'body' ).on( 'submit.edit-post', '#post', function () { | |
// If all three checkboxes are not checked, | |
if ( ! $('#checkbox-one').attr('checked') && ! $('#checkbox-two').attr('checked') && ! $('#checkbox-three').attr('checked') ) { | |
// Show the alert. | |
window.alert( 'Checking one of the checkboxes is required.' ); | |
// Hide the spinner. | |
$( '#major-publishing-actions .spinner' ).hide(); | |
// The buttons get "disabled" added to them on submit. Remove that class. | |
$( '#major-publishing-actions' ).find( ':button, :submit, a.submitdelete, #post-preview' ).removeClass( 'disabled' ); | |
// Focus on the first checkbox field. | |
$( "#checkboxOne" ).focus(); | |
// Prevent the create/update post form from being submitted. | |
return false; | |
} | |
}); | |
}); | |
}( jQuery ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment