Q: How to validate form created in bootbox message? I am using bootbox.js. It allows user to create a form in it's 'message' part. But, I'd like to do some validation using jquery before I click submit button.
This is the bootbox:
bootbox.confirm({
   title    : "Choose Item:",
   message  : 
            "<?php 
                echo "<form id='f_item'>";
                echo "<h3>Item: </h3><br/>";
                foreach($item as $row_item){
                    echo "<input type='checkbox' name='item' class='cek_item' value='".$row_pic->item."' />";
                }
                echo "</form>";
            ?>",
 buttons    : {
                cancel  : { label: '<i class="fa fa-times"></i> Batal' },
                confirm : { label: '<i class="fa fa-check"></i> OK'}
            },
 callback: function (result) {
                //If OK button is pressed
                if(result == true){
                   /*SENT FORM CODE*/
                }
            }
        });

Without adding some validation form submit is working. But, I do not know where to put the validation script.
This is a test script
$(".cek_item").on('change',function(event){ alert($(this).val()+" is choosen"); });
where do I should put this script?
THe validation I'd like to do is:


*

*If first item is first checked, the rest of the item is cannot be
checked.

*If not the first item is first checked, then user cannot check the
first item.


A: You're kind of abusing the bootbox.confirm function, as it's not really meant to have form content. That being said, you would add your validation where you have /*SENT FORM CODE*/ - if you return false from that callback the modal won't close, so something like:
callback: function (result) {
    //If OK button is pressed
    if(result == true){
        /*SENT FORM CODE*/

        $("#f_item").validate();

        if($("#f_item").valid()) {
            /* form is valid */
        }
        else {
            /* form is not valid */
            return false;
        }
    }
}

This assumes you're also using jQuery Validation.
