问题描述
问题:
"kartik-v \ tree-manager"使用的"kartik-v \ yii2-dialog"会覆盖Sweetalert对话框/消息框.
The 'kartik-v\yii2-dialog' which is used by 'kartik-v\tree-manager' overrides Sweetalert dialog/message box.
为了使用SweetAlerts,如何禁用树视图管理器的依赖性'kartik-v \ yii2-dialog'?
How does one disable the treeview-manager's dependency 'kartik-v\yii2-dialog' in order to use SweetAlerts?
尝试:
'assetManager' => ['bundles' => [ 'kartik\dialog\DialogAsset' => ['js' => [],], ... ,
Sweetalert开始在网格中工作并确认事件,但是treemanager不再起作用(未捕获的ReferenceError:未定义KrajeeDialog)
Sweetalert starts working in grids and confirm events, but then treemanager no longer works (Uncaught ReferenceError: KrajeeDialog is not defined)
在图片中:
拥有:
想要:
任何输入将不胜感激.
更新:
这里是有效的替代代码,但是现在kartik \ yii2-dialog会随后加载并覆盖此代码:
Here is the override code, which has worked, but now kartik\yii2-dialog is loaded afterward and overrides this:
yii.confirm = function(message, okCallback, cancelCallback) {
if (message.constructor === Array) {
swal(
{
html: true, // SweetAlert1
title: message[0],
text: message[1],
//html: message[1], // SweetAlert2
//confirmButtonColor: '#E80000',
confirmButtonColor: message[3],
//type: 'warning',
type: message[2],
showCancelButton: true,
cancelButtonText: 'Avbryt',
closeOnConfirm: true,
allowOutsideClick: true,
buttonsStyling: false,
},
okCallback
);
} else {
swal(
{
html: true, // SweetAlert1
title: message,
type: 'warning',
showCancelButton: true,
cancelButtonText: 'Avbryt',
closeOnConfirm: true,
allowOutsideClick: true,
buttonsStyling: false,
},
okCallback
);
}
};
confirm = function(message, okCallback, cancelCallback) {
if (message.constructor === Array) {
swal(
{
html: true, // SweetAlert 1
title: message[0],
text: message[1],
//html: message[1], // SweetAlert2
//confirmButtonColor: '#E80000',
confirmButtonColor: message[3],
//type: 'warning',
type: message[2],
showCancelButton: true,
cancelButtonText: 'Avbryt',
closeOnConfirm: true,
allowOutsideClick: true,
buttonsStyling: false,
},
okCallback
);
} else {
swal(
{
html: true, // SweetAlert 1
title: message,
type: 'warning',
showCancelButton: true,
cancelButtonText: 'Avbryt',
closeOnConfirm: true,
allowOutsideClick: true,
},
okCallback
);
}
};
yii.alert = function(message, okCallback, cancelCallback) {
swal(
{
title: message,
type: 'warning',
showCancelButton: false,
closeOnConfirm: true,
allowOutsideClick: false,
buttonsStyling: false,
},
okCallback
);
};
alert = function(message, okCallback, cancelCallback) {
swal(
{
title: message,
type: 'warning',
showCancelButton: false,
closeOnConfirm: true,
allowOutsideClick: false,
buttonsStyling: false,
},
okCallback
);
};
推荐答案
尽管TreeView
中的krajeeDialogSettings
提供了一个选项,可以通过使用来控制yii2-dialog
Although there is an option provided as krajeeDialogSettings
in TreeView
which controls the yii2-dialog
via using,
'krajeeDialogSettings' => ['overrideYiiConfirm' => true, 'useNative' => true],
根据文档,它应该可以工作,但是对我来说,它不起作用,并且yii2-dialog
总是会覆盖Sweetalert确认,我想从树状视图中排除提示或yii2-dialog并删除依赖关系不是那么直接,因为调用是嵌套和集成在Treeview脚本中的.
According to the docs it should work but for me, it didn't worked, and the yii2-dialog
always overrode the sweetalert confirm, I wanted to rule out the prompt or the yii2-dialog from the treeview and for that removing the dependency is not that straight forward because the calls are nested and integrated in the Treeview script.
因此,我必须重写加载TreeView
小部件的krajeeDialog.confirm
,以便每当调用krajeeDialog.confirm
时,都会调用我的自定义确认对话框.
So, I had to override the krajeeDialog.confirm
where i was loading the TreeView
widget so that whenever the krajeeDialog.confirm
is called my custom confirm dialog would be called.
只需在要加载TreeView
小部件的视图顶部添加以下内容.
Just add the below on the top of the view where you are loading the TreeView
widget.
<?php
$js = <<< JS
krajeeDialog.confirm = function (message, callback) {
swal({
title: message,
type: "warning",
showCancelButton: true,
closeOnConfirm: true,
allowOutsideClick: true
}, callback);
}
JS;
$this->registerJs($js, yii\web\view::POS_READY);
尽管我不喜欢双重方法,但这是唯一对我有用的方法,也许其他人可以发布更好的解决方案.
Although i didnt like the dual approach but that was the only one that worked for me, maybe someone else could post a better solution.
这篇关于如何在Yii2中禁用/覆盖依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!