The 'pluginOptions["url"]' property has not been set - php

I have a problem with Kartik/DepDrop. I have used it many times in the past but are now having an issue
My view
'contentBefore'=>'<legend class="text-info"><small>Client Info</small></legend>',
'attributes'=>[ // 2 column layout
'model'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>ArrayHelper::map(\app\models\Models::find()->All(), 'id','name'), 'options'=>['prompt'=>'Please Select..','id'=>'model']],
'field'=>[
'type'=>Form::INPUT_WIDGET,
'widgetClass'=>DepDrop::classname(),
'options' => ['id'=>'field'],
'pluginOptions' => [
'depends' => ['model'],
'placeholder' => 'select ...',
'url' => Url::to(['dd-field'])
],
],
'related_value'=>['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter Value...']],
]
And the error shows this
_form.php at line 49 – yii\base\Widget::widget(['model' => app\models\RelatedFields, 'form' => kartik\form\ActiveForm, 'autoGenerateColumns' => true, 'rows' => [['contentBefore' => '<legend class="text-info"><small...', 'attributes' => ['model' => ['type' => 'dropdownList', 'items' => [1 => 'Clients', 2 => 'InvoiceItems', 3 => 'Invoices', 4 => 'Notes', ...], 'options' => ['prompt' => 'Please Select..', 'id' => 'model']], 'field' => ['type' => 'widget', 'widgetClass' => 'kartik\depdrop\DepDrop', 'options' => ['id' => 'field'], 'pluginOptions' => ['depends' => ['model'], 'placeholder' => 'select ...', 'url' => '/related-fields/dd-field']], 'related_value' => ['type' => 'textInput', 'options' => ['placeholder' => 'Enter Value...']]]], ['attributes' => ['actions' => ['type' => 'raw', 'value' => '<div style="text-align: right; m...']]]], ...])
If you look at the plugin options it is being passed
'pluginOptions' => ['depends' => ['model'], 'placeholder' => 'select ...', 'url' => '/related-fields/dd-field']
Any ideas anyone.

Found the issue, as i am using FormGrid, the pluginOptions and htmlOptions all need to be inside an options array like this
'field'=>[
'type'=>Form::INPUT_WIDGET,
'widgetClass'=>DepDrop::classname(),
'options' => [
'options'=> ['id' => 'field'],
'pluginOptions' => [
'depends' => ['model'],
'placeholder' => 'select ...',
'url' => '/related-fields/dd-field'
],
],
],

Related

Yii2 - create gridview customizing "model/style" for all gridview and call the style

I have customized my gridview in Yii2 to show columns, headers, and pager in a certain way
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'filterSelector' => 'select[name="per-page"]',
'tableOptions'=> ['class'=>'table datatable-header-footer datatable-header-footer'],
'showFooter' => true,
'layout'=>"{items}\n\n{summary}\n\n<div class='text-right'>{pager}</div>\n",
//'summary' => "{begin} - {end} {count} {totalCount} {page} {pageCount}",
'summary' => " <br/> Affichage de {begin} à {end} des {totalCount} lignes <br/> <br/>",
'formatter' => ['class' => 'yii\i18n\Formatter','nullDisplay' => ' - '],
'pager' => [
'nextPageLabel' => '→',
'prevPageLabel' => '←',
'firstPageLabel' => true,
'maxButtonCount' => 5,
'lastPageLabel' => true
],
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
//'id', ...
['class' => 'yii\grid\ActionColumn',
'contentOptions' => ['style' => 'width:10%;'],
'header'=>'Actions',
'template' => '{all}',
'buttons' => [
'all' => function ($url, $model, $key) {
return ButtonDropdown::widget([
'encodeLabel' => false,
'label' => 'Choisir',
'dropdown' => [
'encodeLabels' => false,
'items' => [
[
'label' => \Yii::t('yii', '<i class="icon-search4"></i> Details'),
'url' => ['view', 'id' => $key],
],
[
'label' => \Yii::t('yii', '<i class="icon-pencil5"></i> Modifier'),
'url' => ['update', 'id' => $key],
'visible' => true,
],
[
'label' => \Yii::t('yii', '<i class="icon-list"></i> Annonces'),
'url' => ['annonces', 'agence_id' => $key],
'visible' => true,
],
[
'label' => \Yii::t('yii', '<i class="icon-list2"></i> Agents'),
'url' => ['professionnels', 'agence_id' =>$key],
'visible' => true,
],
[
'label' => \Yii::t('yii', '<i class="icon-bin"></i> Supprimer'),
'linkOptions' => [
'data' => [
'method' => 'post',
'confirm' => \Yii::t('yii', 'Are you sure you want to delete this item?'),
],
],
'url' => ['delete', 'id' => $key],
'visible' => true, // same as above
],
],
'options' => [
'class' => 'dropdown-menu-right', // right dropdown
],
],
'options' => [
'class' => 'btn-default',
'style' => 'padding-left: 5px; padding-right: 5px;', // btn-success, btn-info, et cetera
],
'split' => true,
]);
Im wondering if there is a way to create a gridview "style" so I can call and apply this style to every gridview in the project !
Yes, extend GridView class with your own, set all properties, override anything you need and use your class instead of default GridView.

yii2 grid filter type not working

I am using kartik grid lib in yii2
This works.
[
'attribute' => 'status',
'filterType' => GridView::FILTER_SELECT2,
'filter' => ['Active' => 'Active', 'In Active' => 'In Active'],
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Select'],
]
But this doesn't
[
'attribute' => 'status',
'filterType' => '\kartik\widgets\Select2',
'filter' =>['Active' => 'Active', 'In Active' => 'In Active'],
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Select'],
]
Why ? I need to use the point 2 approach. But it is not working.
Changed filter type to '\kartik\select2\Select2' and it worked.
usa 'filterType' =>GridView::FILTER_SELECT2, el composer usado es use kartik\grid\GridView;
'filterType' => GridView::FILTER_SELECT2,
'filter' => ArrayHelper::map(Entidad::find()->asArray()->all(),'id', 'nombre'),
filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Selección'],

Yii2: Combining Kartik's FileInput & Kartik's DetailView

I'm trying single-file uploads using Kartik's FileInput.
Things go fine when doing this through standard create form as the following returns non-null:
$filedata = UploadedFile::getInstance($model, 'filedata');
However it always returns null when going into Kartik's DetailView in edit mode and trying to update the file.
In view.php I have:
[
'attribute' => 'filedata',
'visible' => Yii::$app->user->can('doIt'),
'type' => DetailView::INPUT_FILEINPUT,
'rowOptions' => ['class' => 'kv-view-hidden'],
'widgetOptions' => ['options' => ['accept' => 'application/pdf'],
'pluginOptions' => [
'showUpload' => false,
'allowedFileExtensions' => ['pdf'],
'initialCaption' => $model->filename,
],
'pluginEvents' => [
'filecleared' => <whatever>,
'fileloaded' => <whatever>,
],
],
],
while in _form.php (which does work):
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'filedata')->widget(FileInput::classname(), [
'options' => ['accept' => 'application/pdf'],
'pluginOptions' => [
'showUpload' => false,
'allowedFileExtensions' => ['pdf'],
'initialCaption' => $model->getOldAttribute('filename'),
],
'pluginEvents' => [
'filecleared' => <whatever>,
'fileloaded' => <whatever>,
],
])
?>
Any ideas? (BTW, don't know whether 'multipart/form-data' is needed somehow in view.php as it is in _form.php, so anyone confirming this and giving some details should be welcome).
Of course, multipart/form-data is needed both in _form.php and view.php as well, as follows:
'formOptions' => ['options' => ['enctype' => 'multipart/form-data']],
'attributes' => [
...
[
'attribute' => 'filedata',
'visible' => Yii::$app->user->can('doIt'),
'type' => DetailView::INPUT_FILEINPUT,
'rowOptions' => ['class' => 'kv-view-hidden'],
'widgetOptions' => ['options' => ['accept' => 'application/pdf'],
'pluginOptions' => [
'showUpload' => false,
'allowedFileExtensions' => ['pdf'],
'initialCaption' => $model->filename,
],
'pluginEvents' => [
'filecleared' => <whatever>,
'fileloaded' => <whatever>,
],
],
],
....
]

Yii2 Editable Widget custom attribute

i am working with Yii2 and using Editable Widget
My code is below
Editable::widget([
'id' => 1,
'name' => 'assignTo',
'value' => 1,
'url' => 'url here',
'type' => 'select',
'mode' => 'inline',
'clientOptions' => [
'toggle' => 'dblclick',
'emptytext' => 'Unassigned',
'placement' => 'right',
'select2' => [
'width' => '124px'
],
'source' => 1,
'value' => 1,
],
]);
i want to add custom attribute on that generated html tag. i have tried as below but its throw error
Editable::widget([
'id' => 'assignTo_'.$todo->id,
'name' => 'assignTo',
'redirect_url' => 'custom_attriute', // this is custom attribute that i need
'class' => 'my own custom class', // this is custom attribute that i need
'value' => 1,
'url' => 'url here',
'type' => 'select',
'mode' => 'inline',
'clientOptions' => [
'toggle' => 'dblclick',
'emptytext' => 'Unassigned',
'placement' => 'right',
'select2' => [
'width' => '124px'
],
'source' => 1,
'value' => 1,
],
]);
and also i want to add my own class in the generated html i have tried same as above but its not working.
is there any way to make it possible what i want?
dosamigos\editable\Editable extends yii\widgets\InputWidget which has an $options variable that holds:
The HTML attributes for the input tag.
Editable::widget([
'id' => 'assignTo_'.$todo->id,
'name' => 'assignTo',
'options' => [
'redirect_url' => 'custom_attriute', // this is custom attribute that i need
'class' => 'my own custom class', // this is custom attribute that i need
],
'value' => 1,
'url' => 'url here',
'type' => 'select',
'mode' => 'inline',
'clientOptions' => [
'toggle' => 'dblclick',
'emptytext' => 'Unassigned',
'placement' => 'right',
'select2' => [
'width' => '124px'
],
'source' => 1,
'value' => 1,
],
]);

Preselecting an option from a select field in a fields array?

Observe the following $fields array, which is used as an input form in a blade:
$fields = [
'user_id' => [
'label' => 'Opportunity Owner' . $req,
'type' => 'select',
'class' => 'select2',
'opts' => User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()
],
'name' => [
'label' => 'Opportunity Name' . $req,
],
'agent_id' => [
'label' => 'Agent',
'type' => 'select',
'class' => 'select2',
'textAsValue' => false,
'opts' => array_replace([0 => '-- Select Sales Rep --'],
User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()),
],
'description' => [
'label' => 'Description',
'type' => 'textarea'
],
[
'type' => 'submit',
'label' => 'Save',
'class' => 'btn btn-primary !important'
]
];
In the 'agent_id' part, I'd like to pre-select a value if the user has a value preassigned. I know how to get the info from the user, but I am lost as to how to 'select' an option in the array within the 'agent_id' field. I need all options to show in the select, but I want to be able to have one 'selected' based on the agent_id number linked to the user. I tried the following:
'agent_id' => [
'label' => 'Agent',
'type' => 'select',
'class' => 'select2',
'textAsValue' => false,
'opts' => array_replace([0 => '-- Select Sales Rep --'],
User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()),
'selected' => {{appropriate number here}}
],
But that did not work. How could I go about doing this?
Add selected value without any index.
Try this:
'agent_id' => [
'label' => 'Agent',
'type' => 'select',
'class' => 'select2',
'textAsValue' => false,
'opts' => array_replace([0 => '-- Select Sales Rep --'],
User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()),
{{appropriate number here}}
],

Categories