Remove OK button from kartik-v custom dialog - twitter-bootstrap-3

I tried to create a custom dialog using yii2-dialog, one of the kartik-v widgets. I want to create this dialog with a single button: Statistics so, using the documentation provided in the demo, I wrote the code below.
The problem is that the dialog I get has two buttons instead of one and I CAN NOT get rid of the OK button.
My questions are: is there any way to create a custom dialog using yii2-dialog with a single button? and if possible, how can I achieve this?
use kartik\dialog\Dialog;
use yii\web\JsExpression;
echo Dialog::widget([
'libName' => 'krajeeDialogCust',
'overrideYiiConfirm' => false,
'options' => [
'size' => Dialog::SIZE_LARGE,
'type' => Dialog::TYPE_SUCCESS,
'title' => 'My Dialog',
'message' => 'This is an entirely customized bootstrap dialog from scratch.',
'buttons' => [
[
'id' => 'cust-btn-1',
'label' => 'Statistics',
'action' => new JsExpression("function(dialog) {
dialog.setTitle('Title 1');
dialog.setMessage('This is a custom message for button number 1');
}")
],
]
]
]);
// button for testing the custom krajee dialog box
echo '<button type="button" id="btn-custom" class="btn btn-success">Custom Dialog</button>';
// javascript for triggering the dialogs
$js = <<< JS
$("#btn-custom").on("click", function() {
krajeeDialogCust.dialog(
"Welcome to a customized Krajee Dialog! Click the close icon on the top right to exit.",
function(result) {
// do something
}
);
});
JS;
// register your javascript
$this->registerJs($js);
And this is what I'm getting:

You need to use dialogDefaults option, according to the docs the configuration options to be setup as defaults for the bootstrap dialog (applicable when useNative is false). and the default value for useNative is false until you explicitly set to true.
Update your Dialog definition to below and override the buttons property in the dialogDefault option as the plugin sets the ok and cancel buttons by default.
echo Dialog::widget ( [
'libName' => 'krajeeDialogCust' ,
'overrideYiiConfirm' => false ,
'dialogDefaults' => [
Dialog::DIALOG_OTHER => [
'buttons' => ''
]
] ,

Related

Yii2 register Js set Type and remove jquery

i want to have script tag like this for each View
<script type="application/ld+json">
/****** my code
</script>
with
$this->registerJs(....)
i get this kind of code:
<script>jQuery(function ($) {
.....
});</script>
how to add diffrent type and how to remove jQuery..?
By default registerJs() is using $position = View::POS_READY and this one is registering automatically jQuery asset. If you don't want this you can use:
registerJs($js, \yii\web\View::POS_HEAD) - to place JS in the head part
registerJs($js, \yii\web\View::POS_BEGIN) - to place JS in the beginning of body part
registerJs($js, \yii\web\View::POS_END) - to place JS in the end of body part
Unfortunately all these will add your script in the standard <script> tag without the type.
To achieve this you must add it manually either by placing the <script...> by yourself or by calling \yii\helpers\Html::script($js, ['type' => 'application/ld+json']) in your view or layout file.
I use this in the layout. Using blocks allows me to replace this for other schema.org in other pages.
<?= Html::script(isset($this->blocks['schema'])
? $this->blocks['schema']
: \yii\helpers\Json::encode([
'#context' => 'https://schema.org',
'#type' => 'WebSite',
'name' => Yii::$app->name,
'image' => $this->image,
'url' => $this->url,
'descriptions' => $this->description,
'author' => [
'#type' => 'Organization',
'name' => Yii::$app->name,
'url' => Yii::$app->homeUrl,
'telephone' => Yii::$app->params['phone'],
]
]), [
'type' => 'application/ld+json',
]) ?>
Simply use Html::script($js, $options).
Consider the usage of Json::encode() to avoid writing JS in a PHP
file. It's prettier for me that way, and also makes variable
interpolation easier.
In this example you see a lot of $this->image|description|url
because I'm using https://github.com/daxslab/yii2-taggedview to extend the
yii\web\View with more attributes in order to make automate Opengraph
and Twitter Cards tags generation.

Yii2 Nav widget doesnt support routes with baseUrl

1) I have my Yii2 in subfilder, so all my link starts from Yii/, like http:/localhost/Yii/settings/usertype-activitytype/type/3
2) request component config
'request' => [
'cookieValidationKey' => 'somecookiekey',
'baseUrl' => '/Yii',
],
3) Trying to build Menu, current route is http:/localhost/Yii/settings/usertype-activitytype/type/1 the 1 is id in route, and I should specify current route as Yii::$app->request->pathInfo for Nav widget
Attempt 1 - no bracets as string NOT FIND ACTIVE ELEMENT
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => Url::current(['id' => $userType->id]),
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
Attempt 2 - use bracets as route NOT FIND ACTIVE ELEMENT
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => [Url::current(['id' => $userType->id])]
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
Attempt 3 - remove baseUrl from generated route FIND ACTIVE ELEMENT !!!
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => [str_replace('Yii/', '', Url::current(['id' => $userType->id]))]
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
So you should notice I have to use dirty hack to force Nav work with generated Url, it seems very unconvient.
The question is - is there are ways to force NAV widget to recognize current active item ?
If you want buil an url based on your param you should use Url::to()as
'url' => Url::to(your-controller/your-view', ['id' => $userType->id]),
so accessing the view type for controller usertype-activitytype
'url' => Url::to('usertype-activitytype/type', ['id' => $userType->id]),
current Creates a URL by using the current route and the GET parameters.
and remember that
By Design UrlManager always prepends base URL to the generated URLs.
By default base URL is determined based on the location of entry
script. If you want to customize this, you should configure the
baseUrl property of UrlManager.
Looking to your comment the url is correcly formed .. then if you need http:/localhost/Yii instead of Yii then you can:
don't set so the localhost ... url is atomatically created
OR add the proper base url configureation as http:/localhost/Yii/ in config /main and remember that you can use main.php and main-local.php for manage different congiguration

drupal generate fpdf files

I create website based on drupal 7 with module to generate pdf - i use fpdf library.
I dont know how I can make form to send some data to node where i have php code for generate pdf.
Also i still get error message:
FPDF error: Some data has already been output, can't send PDF file (output started at Z:\xampp\htdocs\domain\includes\common.inc:2748)
where i found:
ob_flush();
when i try change it to
ob_clean()
all nodes generate pdf :/
You can try use other module which is a simple - pdf_using_mpdf
With this module you can get PDF of some node calling www.YOUR_SITE.DOMAIN/node/NID_ID/pdf - where NID_ID is the id of node what you want to render as PDF.
Or also you can use hook_menu() if you need render as PDF only some fields of your node - add your item like
$items['%node/create_pdf'] = array(
'title' => '',
'description' => '',
'page callback' => 'custom_callback_create_pdf',
'page arguments' => array(1),
'access callback' => 'node_access',
'type' => MENU_CALLBACK,
);
Define you callback like
function custom_callback_create_pdf($node) {
// Check if current node has needed field.
if (isset($node->field_my_custom_field_of_node)) {
// Render only field 'field_my_custom_field_of_node';
$view = node_view($node);
$output = render($view['field_my_custom_field_of_node']);
return pdf_using_mpdf_api($output, $node->title);
}
else {
return pdf_using_mpdf_api("<html><body>Current page do not required field.</body></html>", $node->title);
}
}
and print button for download:
$pdf_button = l(t('Download as PDF'), 'node/' . $node->nid . '/create_pdf', array(
'attributes' => array(
'target' => '_blank',
'class' => array('render_as_pdf'),
),
));
echo '<p>' . $pdf_button . '</p>';

how to bind Kendo grid custom command click event?

How can we use custom delete confirmation message box while working with Kendo UI Grid ?
I am working on ASP.NET MVC4 application.And below is the code of my Kendo Grid.
I want to use custom confirmation message box in place of default Destroy command confirmation box.And for that i am using custom command in place of Destroy command.
But my problem is i want to fire one serer side action method in .Datasource section(just like in below code for Destroy command),but i don't know how to fire that action with Custom command.
Can any one help me out on this ?
<script id="XYZTemplate" type="text/kendo-tmpl">
#(Html.Kendo().Grid<Gts.Core.Dto.XYZDto>()
.Name("XYZItem")
.Columns(columns =>
{
columns.Bound(e => e.ID).Width(97).ClientTemplate("<span style=\"float:left\">\\#=Number\\#</span>").HtmlAttributes(new { style = "text-align:left;" });
columns.Bound(e => e.Qty).Width(30);
//columns.Command(command => { command.Destroy(); });
columns.Command(command => command.Custom("Delete").Click("deleteRow"));
})
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.ID))
.Read(read => read.Action("Items_Read", "Product", new { ID = "#=ID#", productId = "#=FKProductID#" }))
//.Destroy(update => update.Action("Items_Destroy", "Product"))
)
// .Events(events =>
events.DataBound("dataBoundChild").Edit("dataBoundEdit").Remove("deleteProductItemChild").Save("datasourceChange"))
.Events(events => events.DataBound("dataBoundChild").Edit("dataBoundEdit").Save("datasourceChange"))
.Editable(editable => editable
.Mode(GridEditMode.InCell)
.DisplayDeleteConfirmation(false))
.ToClientTemplate()
)
</script>
In your deleteRow function, after the you removed the row from grid, use the following code to sync the grid. The sync function will fire server-side actions accordingly depends on the changes you have made to the grid.
$("#XYZItem").data("kendoGrid").dataSource.sync();

Errors on submit in a popup box?

How to show the validation errors in a form in a pop dialogue box?Instead of showing it in the top of the form as a separate div, i want to show those errors in a popup dialogue box so that user clicks okay and dismiss the box.How to do this in yii?
Register your own javascript function name to the afterValidate, which is one of the options in clientOptions property in CActiveForm form class.
Your form declaration should have
'clientOptions' => array(
'validateOnSubmit' => true,
'afterValidate' => 'js:myFunc',
),
And Your form will appear like bellow
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'a-form',
'enableClientValidation' => true,
'enableAjaxValidation' => true,
'errorMessageCssClass' => 'required',
'clientOptions' => array(
'validateOnSubmit' => true,
'afterValidate' => 'js:myFunc',
),
));
?>
------Your form fields------------
------Your form fields------------
------Your form fields------------
<?php $this->endWidget(); ?>
Now, Your myFunc code:
<script type="text/javascript" charset="utf-8">
function myFunc(form, data, hasError)
{
if (hasError)
{
var errors='';
$.each(data, function(obj)
{
errors+=data[obj][0]+"\n";
});
alert(errors);
// Do what ever you want
return true;
}
}
</script>
If you enable client side validation, then you will get error message under textbox, dropdown. There is no in-built option for poping up error message.
still if you need popup error message display, then you have to do with jquery. Then add in Yii forum to help others as well :-)
Refer this link (Yii forum) for details about client side validation
You can build the HTML view yourself with a custom CFormModel and use getError() method in a modal popup.
See : http://www.yiiframework.com/doc/api/1.1/CModel#getError-detail
and : http://www.yiiframework.com/doc/api/1.1/CFormModel