drgullin / icheck

Highly customizable checkboxes and radio buttons (jQuery & Zepto)
http://fronteed.com/iCheck
7.38k stars 1.62k forks source link

Checkbox delete confirmation callbacks #278

Open murderaven opened 9 years ago

murderaven commented 9 years ago

Hi,

I want to control deleting actions in form areas. My old controller works fine and I try to modify it as iCheck callbacks but it does not work properly. Whats wrong?

Form

<input type="checkbox" id="del" name="del" value="YES">
<label for="del">Delete</label>

Control

$('input[name=del]').on('ifChanged', function(e){

        if(confirm('Are you sure to delete?')){
            $(this).iCheck('check');
        }else{
            $(this).iCheck('uncheck');
        }
});

Regards.

kalelc commented 9 years ago

@murderaven remember call update method iCheck to update input element.

$(this).iCheck('update');

:)

chmutoff commented 8 years ago

Hi there!

I'm trying to do the same. I want the user to confirm that he wants to check this box, but update it's not working inside of the event. I must manually run it after event finishes.

$(document).ready(function(){
        $('#renew').on('ifChecked', function(e){
        if(confirm('Are you want to renew?')){
            $(this).iCheck('check');
        }else{
            $(this).iCheck('uncheck');
        }
        $(this).iCheck('update');
    });
});

If I check the box and press Cancel, it still checked visually (but really is unchecked). I need to run the update method from somewhere else but i dont know from where! Please, help me.

Regards, Anton.

kemalatila commented 8 years ago

I need help in same issue

kemalatila commented 8 years ago

I solved. use with http://t4t5.github.io/sweetalert/


        window.selected_radio = $('input[type="radio"]:checked');

        $('input').on('ifClicked', function (e) {
            swal({
                title: "Are You Sure?",
                text: "Bla Bla .....",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Delete",
                cancelButtonText: "No",
                closeOnConfirm: true
            }, function (isConfirm) {
                if (isConfirm) {

                window.selected_radio = $(this);

                    var formData = {sit_user: this.value};

                    $.ajax({
                        url: "/ajax_url",
                        type: "GET",
                        data: formData,
                        success: function (data, textStatus, jqXHR) {

                        }, error: function (jqXHR, textStatus, errorThrown) {

                        }

                    });

                }else{
                    window['selected_radio'].iCheck('check');
                }
            });
        });