- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 yii2mod/yii2-sweet-alert在我的项目中,我在基础和高级主题上使用它,我喜欢它。
问题。我怎样才能更改网格默认确认对话框,这是一个普通的 javascript 确认,以便使用 Sweet-alert让它看起来更好?
我已经尝试修改删除按钮的模板,因为如果你想更改消息,你将执行以下操作:
[
'class' => ActionColumn::className(),
'template' => '{update}{delete}',
'buttons' => [
'delete' => function($url, $model){
return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $model->id], [
'class' => '',
'data' => [
'confirm' => 'Are you absolutely sure ? You will lose all the information about this user with this action.',
'method' => 'post',
],
]);
}
]
]
但我没有成功将确认消息从 javascript 更改为甜蜜警报。
此外,我正在尝试作为第二个选项,使其与 Krajee/ Grid and actionColumn 一起使用但仍然可以让它工作 «这是第二个正在工作的选项,来做到这一点»。
[
'class' => 'kartik\grid\ActionColumn',
'viewOptions' => ['hidden' => true],
'updateOptions' => ['title' => 'Edit events', 'data-toggle' => '??'],
'deleteOptions' => ['title' => 'delete your event', 'data-toggle' => 'I am Lost here'],
],
请问如何改变这种行为?
更多关于如何解决的信息 - 感谢 @muhammad-omer-aslam
在我的例子中,在您的公用文件夹中创建一个 js 文件/backend/web/js/confirmSwal.js
并添加提供的代码:
添加这些行
yii.confirm = function (message, okCallback, cancelCallback) {
swal({
title: message,
type: 'warning',
showCancelButton: true,
closeOnConfirm: true,
allowOutsideClick: true
}, okCallback);
};
将此添加到您的 AppAssets 上
/backend/assets/AppAssets.php
public $js = [
'/js/confirmSwal.js',
];
就是这样,它的效果很漂亮。
再次感谢穆罕默德。
最佳答案
更新 2
只需更正您需要做的代码
okCallback.call()
或添加括号 ()
如 'okCallback()`cancelCallback.call()
或添加括号 cancelCallback()
在 .then((selection)=>{})
里面,它是一个匿名函数,需要调用而不是仅仅使用 okCallback
所以里面的代码.then((selection)=>{})
变成了
if(selection){ okCallback.call();}else{ cancelCallback.call();}
更新
sweetalert 2.0
版本中不推荐使用以下选项,
回调
支持promise
:如果用户单击确认按钮, promise 将解析为 true
。如果警报被解除(通过在警报外部单击), promise 将解析为 null
。
allowClickOutside
现在是 closeOnClickOutside
。
showCancelButton
和 showConfirmButton
。相反,您可以设置 buttons: true
以显示两个按钮或设置 buttons: false
以隐藏所有按钮。默认情况下,仅显示确认按钮。swal("Hello world!")
),该参数将是模式的 text
而不是它的 title
。type
和 imageUrl
已替换为单个 icon
选项。如果您使用的是简写版本 (swal("Hi", "Hello world", "warning")
),则无需更改任何内容。因此,如果您使用 2.x
版本或从 1.x
升级,您可以将代码更改为以下内容。
yii.confirm = function (message, okCallback, cancelCallback) {
swal({
text: message,
icon: 'warning',
buttons : {
cancel : {
text : "Oops! No",
value : null,
visible : true,
className : "",
closeModal : true
},
confirm : {
text : "Delete It Already",
value : true,
visible : true,
className : "",
closeModal : true
}
},
closeOnClickOutside: true
}).then((selection) => {
if(selection){okCallback;}else{cancelCallback;}
});
}
您可以使用以下代码覆盖 Yii2 默认的 data-confirm
弹出窗口:
基础是包含 Assets ,然后添加这个 JS:
/**
* Override the default yii confirm dialog. This function is
* called by yii when a confirmation is requested.
*
* @param message the message to display
* @param okCallback triggered when confirmation is true
* @param cancelCallback callback triggered when canceled
*/
yii.confirm = function (message, okCallback, cancelCallback) {
swal({
title: message,
type: 'warning',
showCancelButton: true,
closeOnConfirm: true,
allowOutsideClick: true
}, okCallback);
};
关于php - Yii2:用 Sweet alert 替换 Gridview 使用的默认确认消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49220106/
如何从 sweet.js 宏的参数创建字符串?例如: let foo = macro { rule { $name } => { console.log
如何从参数创建一个字符串到 sweet.js 宏?例如: let foo = macro { rule { $name } => { console.l
用例: 我正在尝试改变 window.alert甜蜜警报。 当我使用 window.alert时,文件上传窗口前出现警告弹出窗口,然后单击“确定”,出现文件上传窗口。 但是,改变后window.ale
如果用户未登录,我一直在尝试进行简单的验证,并尝试在发生这种情况时触发一条甜蜜的警报消息。如果客户尝试将新产品添加到购物车但未登录,则此验证有效。 注意: session 变量是 ASP.NET Co
我的 Sweet Aler 确认对话框有问题。当我单击删除图标时,Sweet Alert 对话框显示不到一秒钟,然后消失并删除该元素。换句话说,我没有机会单击“删除”或“取消”。如何停止这个对话框让我
我想定义一个可转换的甜蜜宏 { a, b } # o 进入 { o.a, o.b } 我目前的尝试是 macro (#) { case infix { { $prop:ident (,) ...
swal({ title: "Log In to Continue", html: true, text: "Username: Password: "
我有一个功能,我可以将我的甜蜜警报对话框装扮起来。我想在很多地方使用它,因此将其设置为如下函数: $rootScope.giveConfirmDialog = function(title,text,
我似乎无法匹配 let function = macro { case infix {$name:ident $[=] | _ ($params ...) { $body ...} } => {
我有一个非常简单的 sweet.js 文件,我正在尝试编译: macro @ { rule { $exp }=>{ + $exp + } } .
我设置了这样的构造函数: ... constructor(props) { super(props); this.state =
下面是我的编码。请告知为什么甜蜜警报只弹出不到 1 秒然后自动重定向到另一个页面。 来自 HTML: $.ajax({ url: "/ABC/AddST/", data: { "use
我有一个带有 php while 循环的 php 页面,在其中我获取用户详细信息和 id。该循环创建按钮,单击这些按钮时,我需要根据其 ID 了解每个按钮的详细信息,如下图所示。 http://tin
我正在使用Sweet Alert JS来提示窗口获取一些输入变量。我试图在函数之外使用这些变量,它们被设置为 NULL,但是当我在函数内部使用它们时,它们被正确设置。我读了一些有关回调函数的内容,但我
我正在尝试编写一个将标记转换为字符串的宏。我当前的宏如下所示: macro stringify { case { $name($token) } => {
我正在使用 Sweet alert library 使用这个库,我发现了奇怪的行为;按键盘的空格键选择警报中的“确认”。但是,在按下“取消”后,在以后的尝试中使用空格键事件“确认”不起作用。(有警报时
我想在宏主体中使用括号来对表达式进行分组。例如: macro m { rule { ($x, $y) } => { $x >>> ($y * 5) } } Sweet.js 删除所有括
我正在创建一个显示非常重要消息的 Sweet Alert,我不希望用户未阅读就关闭它。 因此,为了强调该消息的重要性,我想将“确定”按钮禁用(比方说...)5 秒,这样用户必须至少等待 5 秒才能解除
我在文件“A”中定义了宏。我想在其他文件中使用宏,例如文件 B. 这可能吗?我当然知道我可以在文件 B 中使用宏的编译结果,但我也想在那里使用宏。 一个 macro test { ... } tes
我在一个循环中调用了 sweet alert 函数但是 sweetalert 只显示了一次,我认为它覆盖了之前的 sweetalert,bcz 当我做简单的警报时它确实弹出了两次但是 sweet al
我是一名优秀的程序员,十分优秀!