[英]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-confirm
和data-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.