Skip to content Skip to sidebar Skip to footer

Custom Js Confirm Modals Using Jquery.deferred And Issues With Return Values Based On Buttons

I'm a java developer who has somewhat recently entered the Javascript world, so forgive me if I make some silly mistakes or assumptions. I am attempting to translate our native bro

Solution 1:

I advise you a way like yours, but a little different. I hope it help you.

cutomConfirm: function(text) {
    var d, rendered, template,
    _this = this;

    template = $('#custom_confirm_temp');
    rendered = $.tmpl($(template).template(), {
        text: text || ''
    });

    $.blockUI({
        message: rendered,
        showOverlay: true,
        onUnblock: function() {
            return $(document).unbind('click');
        },
        css: {
          width: '600px',
          height: '150px',
          opacity: '1',
          border: '0',
          backgroundColor: 'none'
        }
    });

    d = $.Deferred();

    rendered.find('#OK').click(function() {
        $.unblockUI();
        return d.resolve();
    });

    rendered.find('#CANCEL').click(function() {
        $.unblockUI();
        return d.reject();
    });

    return d;
}

You need to create your template(with id ="custom_confirm_temp" ) and call when you need.

Post a Comment for "Custom Js Confirm Modals Using Jquery.deferred And Issues With Return Values Based On Buttons"