简体   繁体   English

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

[英]alertify.js - rails custom confirm dialog

How can I customize my rails confirm dialog with alertify? 如何自定义带有alertify的rails确认对话框? I tried this code and regarding to the jquery_ujs it should work: 我尝试了这段代码,并考虑到jquery_ujs应该起作用:

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

example rails call: Rails调用示例:

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

I am fiddling with this override as well and stumbled on this question. 我也对这种覆盖不满意,并且偶然发现了这个问题。 This snippet does not work because the result of alertify.confirm does not get returned to $.rails.confirm . 该代码段无效,因为alertify.confirm的结果未返回到$.rails.confirm

Update: 更新:

After some searching I found a demo by rors . 经过一番搜索,我发现了一个由rors制作的演示。

Important note: In your HTML you will have to have two data-attributes: data-confirm and data-method . 重要说明:在HTML中,您将必须具有两个数据属性: data-confirmdata-method Where data-method can be a RESTful method (GET, POST, PUT, PATCH, DELETE). 数据方法可以是RESTful方法(GET,POST,PUT,PATCH,DELETE)。

Javascript: 使用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: 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