繁体   English   中英

alertify.js-Rails自定义确认对话框

[英]alertify.js - rails custom confirm dialog

如何自定义带有alertify的rails确认对话框? 我尝试了这段代码,并考虑到jquery_ujs应该起作用:

$.rails.confirm = function(msg){
  alertify.confirm(msg, function (e) {
    if (e) {
        return true;
    } else {
       return false;
    }
  });
};

Rails调用示例:

<%= link_to system_communication_gallery_video_path(@gallery.id, video.id), method: :delete, remote: true, confirm: "Are you sure?" do %>

我也对这种覆盖不满意,并且偶然发现了这个问题。 该代码段无效,因为alertify.confirm的结果未返回到$.rails.confirm

更新:

经过一番搜索,我发现了一个由rors制作的演示。

重要说明:在HTML中,您将必须具有两个数据属性: data-confirmdata-method 数据方法可以是RESTful方法(GET,POST,PUT,PATCH,DELETE)。

使用Javascript:

$.rails.allowAction = function(element){
    if( undefined === element.attr('data-confirm') ){
        return true;
    }

    $.rails.showConfirmDialog(element);
    return false;
};

$.rails.confirmed = function(element){
    element.removeAttr('data-confirm');
    element.trigger('click.rails');
};

$.rails.showConfirmDialog = function(element){
    var msg = element.data('confirm');
    alertify.confirm(msg, function(e){
        if(e){
            $.rails.confirmed(element);
        }
    })
};

HAML:

= link_to 'Link title', root_path, {data: {confirm: 'Are you sure you want to go home?', method: 'get'}}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM