Created
July 28, 2017 21:02
-
-
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
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
<?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