[英]How to disable /override dependencies in Yii2
Problem : 问题 :
The 'kartik-v\\yii2-dialog' which is used by 'kartik-v\\tree-manager' overrides Sweetalert dialog/message box. “ kartik-v \\ tree-manager”使用的“ kartik-v \\ yii2-dialog”会覆盖Sweetalert对话框/消息框。
How does one disable the treeview-manager's dependency 'kartik-v\\yii2-dialog' in order to use SweetAlerts? 为了使用SweetAlerts,如何禁用树视图管理器的依赖性'kartik-v \\ yii2-dialog'?
Tried : 尝试过 :
'assetManager' => ['bundles' => [ 'kartik\dialog\DialogAsset' => ['js' => [],], ... ,
Sweetalert starts working in grids and confirm events, but then treemanager no longer works (Uncaught ReferenceError: KrajeeDialog is not defined) Sweetalert开始在网格中工作并确认事件,但treemanager不再起作用(未捕获的ReferenceError:未定义KrajeeDialog)
In Pictures: 在图片中:
Have: 有:
Want: 想:
Any input would be greatly appreciated. 任何投入将不胜感激。
Update: 更新:
Here is the override code, which has worked, but now kartik\\yii2-dialog is loaded afterward and overrides this: 这是有效的替代代码,但是现在kartik \\ yii2-dialog随后被加载并覆盖此代码:
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
);
};
Although there is an option provided as krajeeDialogSettings
in TreeView
which controls the yii2-dialog
via using, 尽管
TreeView
提供了作为krajeeDialogSettings
提供的选项,该选项可通过使用来控制yii2-dialog
,
'krajeeDialogSettings' => ['overrideYiiConfirm' => true, 'useNative' => true],
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. 根据文档,它应该起作用,但是对我来说,它没有起作用,并且
yii2-dialog
始终覆盖sweetalert确认,我想从树状视图中排除提示或yii2-dialog,并且删除依赖项是不是很简单,因为调用是嵌套并集成在Treeview脚本中的。
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
小部件的位置krajeeDialog.confirm
,以便每当调用krajeeDialog.confirm
时, krajeeDialog.confirm
调用我的自定义确认对话框。
Just add the below on the top of the view where you are loading the TreeView
widget. 只需在要加载
TreeView
小部件的视图顶部添加以下内容。
<?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. 尽管我不喜欢双重方法,但这是唯一对我有用的方法,也许其他人可以发布更好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.