Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i am tring to load some jquery code to make validation in the theme customizer. i have created 10 checkboxes to show some info. but i want to limited the user to choose only 5 checkboxes. so i have created jquery code to do so, and this code works fine when i put this code in the chrome console.

jQuery(document).ready(function($){ 
$("#section id input[type=checkbox]").click(function(){
    var countchecked = $("#section id input[type=checkbox]:checked").length;

    if(countchecked >= 2) 
    {
        $('#section id input[type=checkbox]').not(':checked').attr("disabled",true);
    }
    else
    {
        $('#section id input[type=checkbox]').not(':checked').attr("disabled",false);
    }
});
});

what i have missed? which codec i need to use to insert in functions.php that will load some jquery code when the user using customize.php (theme customizer)?

i want to make all the validation before user trying to save all the changes.

thanks for help.

share|improve this question
add comment

1 Answer

Create a /js subfolder in your theme directory, if such does not exist already.
Save your script to a file in said folder.

Then, in functions.php:

if ( is_admin() ) {
    global $pagenow;

    if ( 'customize.php' === $pagenow ) {
        add_action( 'admin_enqueue_scripts', 'wpse107236_enqueue_customizer_script' );
    }
}

function wpse107236_enqueue_customizer_script() {
    wp_enqueue_script(
        'your-script-handle',
        get_template_directory_uri . '/js/your-script.js',
        array( 'jquery' ),
        '1.0',
        true
    );
}

Related Resources:

share|improve this answer
    
Hello Johannes Pille, it seems not working. i try in this way and the "if" here is not working if i write this outside from the "if" "add_action( 'wp_enqueue_scripts', 'wpse107236_enqueue_customizer_script' );" i get "Hello World" i created js fille and put there jQuery(document).ready(function ($) { alert("Hello World"); }); in the same file i have my code i have paste above but it not working. –  someone Jul 20 '13 at 10:29
    
maybe you have some other solution for this? it can be done by php validation if there is a problem to run custom jquery for customizer. thanks –  someone Jul 21 '13 at 4:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.