jeudi 26 mars 2015

Enable buttons of confirmbox when checkbox checked in jquery

This is code in functions.php file.There is a confirmbox to enter value.When i press OK button, the value is saved .But i want user to check checkbox first then value will be entered.This all i had done but the issue is in, when i press ok button without checking checkbox, the alert appears and confirmbox hides at the same time. I want that confirm box will retain its position after alert disappears .



var mess ="abc";

jQuery.confirm({
'title' : '<?php _e('Terms','Theme'); ?>',
'message' : mess ,
'buttons' : {
'<?php _e('OK','Theme'); ?>' : {
'class' : 'button1',
'action': function()
{
if(jQuery('#check').is(":checked")){
post_ok = 1;
jQuery("#my_form_"+id).submit();
return true;
}
else{
alert("select terms and conditions first.");
}
}
},
'<?php _e('No','Theme'); ?>' : {
'class' : 'button2',
'action': function(){ return false; }
}
}
});


confirm.js



(function($){

$.confirm = function(params){

if($('#confirmOverlay').length){
// A confirm is already shown on the page:
return false;
}

var buttonHTML = '';
$.each(params.buttons,function(name,obj){

// Generating the markup for the buttons:

buttonHTML += '<a href="#" class="button '+obj['class']+'">'+name+'<span></span></a>';

if(!obj.action){
obj.action = function(){};
}
});

var markup = [
'<div id="confirmOverlay">',
'<div id="confirmBox">',
'<h1>',params.title,'</h1>',
'<p>',params.message,'</p>',
'<div id="confirmButtons">',
buttonHTML,
'</div></div></div>'
].join('');

$(markup).hide().appendTo('body').fadeIn();

var buttons = $('#confirmBox .button'),
i = 0;

$.each(params.buttons,function(name,obj){
buttons.eq(i++).click(function(){

// Calling the action attribute when a
// click occurs, and hiding the confirm.

obj.action();
$.confirm.hide();
return false;
});
});
}

$.confirm.hide = function(){
$('#confirmOverlay').fadeOut(function(){
$(this).remove();
});
}

})(jQuery);




Aucun commentaire:

Enregistrer un commentaire