Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created July 28, 2017 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tripflex/269bb04c2745580604ca7859eb61c5be to your computer and use it in GitHub Desktop.
Save tripflex/269bb04c2745580604ca7859eb61c5be to your computer and use it in GitHub Desktop.
WP Job Manager Field Editor hide/show field based on checkbox field status with jQuery
<?php
// ^ there should ONLY be one of these at the top of child theme's functions.php file
add_action( 'submit_job_form_start', 'my_custom_jquery_set_field_readonly' );
function my_custom_jquery_set_field_readonly(){
/**
* Replace HIDDENMETAKEY with the meta key of the field you want to hide/show based on checkbox
* Replace CHECKBOXMETAKEY with the meta key of the checkbox field to use
*/
echo "<script>
jQuery( function ( $ ) {
// Set hidden by default
$( '.fieldset-HIDDENMETAKEY' ).hide();
// When checkbox is clicked
$( '#CHECKBOXMETAKEY' ).click( function () {
// Check if it's checked
if ( $( this ).is( ':checked' ) ){
// And show other field
$( '.fieldset-HIDDENMETAKEY' ).show();
} else {
// Otherwise make sure it's hidden
$( '.fieldset-HIDDENMETAKEY' ).hide();
}
});
});
</script>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment