I have a form and I want to change my DynamicModel rule validations depedending on the value chosen in a specific select input. I've read this doc but I don't understand why my code doesn't work. I've tried the following with no results:
MyController
private function createFormModel(){
$model = new DynamicModel([
'indicador',
'mes'
]);
$model->addRule(['indicador'], 'required',['message' => 'This field is required']);
$model->addRule(['mes'], 'string');
$model->addRule(
'mes',
function ($attribute, $params, $validator) use ($model) {
if ($model->indicador == 'semana') {
$model->addError('mes', 'This field is required');
}
}
);
return $model;
}
MyView
<?php $form = ActiveForm::begin(); ?>
<!-- indicador -->
<div class="form-group">
<?= $form->field($model, 'indicador')->widget(Select2::class, [
'options' => ['id'=>'indicador'],
'data' => [
'dia' => 'Actividad por Día',
'semana' => 'Actividad por Semana',
'resumen' => 'Resumen de actividad'
],
'pluginOptions' => [
'placeholder'=>'Seleccionar indicador',
'allowClear' => true
],
]); ?>
</div>
<!-- /.indicador -->
<!-- mes -->
<div id = "semana" class="form-group hidden">
<?= $form->field($model, 'mes')->widget(DepDrop::class, [
'type' => DepDrop::TYPE_SELECT2,
'options' => ['id' => 'mes'],
'select2Options' => ['pluginOptions' => ['allowClear' => true]],
'pluginOptions' => [
'depends' => ['indicador'],
'placeholder'=>'Seleccionar mes',
'url' => Url::to(['/campus/subindicador']),
'loadingText' => 'Cargando ...',
'initialize' => true,
]
]);?>
</div>
<!-- /.mes -->
<?= Html::submitButton('Aplicar filtros', ['class' => 'btn btn-block btn-default']) ?>
<?php ActiveForm::end(); ?>
You need to use when with required validator.
$model = new DynamicModel(['indicador', 'mes']);
$model->addRule(['indicador'], 'required', ['message' => 'This field is required']);
$model->addRule(['mes'], 'string');
$model->addRule(['mes'], 'required', ['when' => function ($dModel) {
return $dModel->indicador == 'semana';
}, 'message' => 'This field is required']);
Related
I'm trying to render a Nav bar (from _tabs.php) onto index.php (view) the controller that is being used is ImportController.php. the _tabs.php file uses the client_id which is basically the function to get the client ID so it can appropriately create the URL with an ID in it. The issue that I'm getting is Trying to get property 'id' of non-object
index.php (view)
<?php
use yii\bootstrap\Html;
use common\components\ActiveForm;
use common\models\User;
use common\models\Client;
$Client= null;
$this->title = 'Import Offline Data Capture data';
?>
<!-- capture partial Nav -->
<br>
<?php if(in_array(Yii::$app->user->identity->role, User::MHM_ROLES)): ?>
<?= $this->render('/client/_tabs', ['Client' => $Client]); ?>
<?php endif; ?>
<?php if(in_array(Yii::$app->user->identity->role, User::CLIENT_ROLES)): ?>
<?= $this->render('//client/partialNavs/appendNav', ['Client' => $Client]); ?>
<?php endif; ?>
<div class="page-header">
<h2>Import data</h2>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body" id="survey-import-container">
<h4 class="text-info">Please select a file to import</h4>
<?php if(count($ImportForm->getErrors('dataErrors'))): ?>
<div class="alert alert-warning">
<p><strong>Sorry, we were unable to process your import. Please revise the following errors and try again:</strong><p><br />
<ul>
<?php foreach($ImportForm->getErrors('dataErrors') as $e): ?>
<li><?= $e; ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<p>The file must follow the exported template, and must be a XLSX document with a maximum of 10,000 rows.</p>
<?php $form = ActiveForm::begin([
'id' => 'import-form',
'options' => [
'enctype' => 'multipart/form-data',
'class' => 'clearfix',
]
]) ?>
<?= $form->field($ImportForm, 'importFile')->fileInput() ?><hr />
<?= Html::submitButton('<span class="glyphicon glyphicon-import"></span> Import & Process Data', ['class' => 'btn btn-primary col-md-6', 'id' => 'import-data-btn']); ?>
<?= Html::a('<span class="glyphicon glyphicon-repeat"></span> Reset', ['import/index'], ['class' => 'btn btn-link col-md-6']); ?>
<?php ActiveForm::end() ?>
<div class="alert alert-danger" style="margin-top: 20px;">Please note: This application does not store any of your imported data. Keep your original spreadsheet to avoid losing data.</div>
</div>
</div>
</div>
</div>
ImportController.PHP
<?php
namespace admin\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\UploadedFile;
use admin\components\Controller;
use admin\models\ImportForm;
use common\models\User;
use common\models\Client;
class ImportController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'actions' => ['index'],
// All actions are access controlled.
'roles' => [
User::ROLE_MHM_ADMIN,
User::ROLE_MHM_USER,
User::ROLE_CLIENT_ADMIN,
User::ROLE_CLIENT_USER,
]
],
],
],
];
}
public function actionIndex($client_id = null)
{
// Get client
$Client = $this->getClient($client_id);
// Ensure client exists for logged in user
if(is_null($Client)) {
throw new BadRequestHttpException('This page does not exist.');
}
$ImportForm = new ImportForm;
// Form posted, validate
if(Yii::$app->request->isPost) {
$ImportForm->importFile = UploadedFile::getInstance($ImportForm, 'importFile');
// Process upload
$ImportForm->upload();
}
return $this->render('index', array(
'ImportForm' => $ImportForm,
));
}
public function actionRenderSuccess()
{
return $this->renderPartial('_success');
}
private function getClient($id, $restriction = null)
{
if(Yii::$app->user->identity->client_id)
{
$id = Yii::$app->user->identity->client_id;
}
$ClientQuery = Client::find()
->andWhere(['id' => $id]);
if ($restriction == 'patronbase') {
$ClientQuery->andWhere(['license_type' => Client::LICENSE_PATRONBASE]);
} else if ($restriction == 'live') {
$ClientQuery->andWhere(Client::LIVE_OR_UPGRADING_CONDITION);
}
$Client = $ClientQuery->one();
if(is_null($Client))
{
throw new NotFoundHttpException('');
}
return $Client;
}
}
_tabs.php
<?php
use yii\bootstrap\Html;
use common\models\Client;
use common\models\User;
use common\models\SurveyInstance;
use common\models\Consent;
use yii\bootstrap\Tabs;
use yii\bootstrap\Nav;
if (Yii::$app->user->isGuest) return;
$getRoute = function($route, $clientParamName, $otherParams = []) use ($Client)
{
$routeParams = [$route];
if (!isset(Yii::$app->user->identity->client_id)) {
$routeParams[$clientParamName] = $Client->id;
}
return array_merge($routeParams, $otherParams);
};
$route = Yii::$app->controller->module->requestedRoute;
$mhmOrClientAdmin = in_array(Yii::$app->user->identity->role, [User::ROLE_MHM_ADMIN, User::ROLE_MHM_USER, User::ROLE_CLIENT_ADMIN]);
$mhmUser = in_array(Yii::$app->user->identity->role, User::MHM_ROLES);
$urlsForConsentSurveyTypes = Consent::getUrlForSurveyTypes();
$items = [
[
'label' => 'Checkout / Enrich',
'url' => $getRoute('dashboard/mhm-rels-dashboard', 'client_id'),
'active' => in_array($route, [
'dashboard/mhm-rels-dashboard',
'survey-instance/api-logs',
'client/activity',
'client/update',
'client/api-settings'
]) || ($route =='consent/index' && Yii::$app->request->get('type')=='cs-tag-tool-consent'),
'encode' => false,
'visible' => $Client->isFullOrUpgrading,
],
[
'label' => 'Checkout / Enrich',
'url' => $getRoute('dashboard/patronbase-dashboard', 'client_id'),
'active' => in_array($route, [
'dashboard/mhm-rels-dashboard',
'dashboard/patronbase-dashboard',
'survey-instance/api-logs',
'client/activity',
'client/update',
'client/api-settings',
'client/patronbase-settings'
]) || ($route =='consent/index' && Yii::$app->request->get('type')=='cs-tag-tool-consent'),
'encode' => false,
'visible' => $Client->license_type === Client::LICENSE_PATRONBASE,
],
[
'label' => 'Capture',
'url' => $getRoute('dashboard/capture-dashboard', 'client_id'),
'active' => in_array($route, [
'dashboard/capture-dashboard',
'client/survey-settings',
'consent/create',
'consent/update',
'question/index',
'client/legal',
'question/create',
'question/update'
]) || ($route =='consent/index' && Yii::$app->request->get('type')=='capture-consent'),
'encode' => false,
],
[
'label' => 'Append',
'url' => $getRoute('dashboard/append-dashboard', 'client_id'),
'active' => in_array($route, [
'dashboard/append-dashboard',
'client/append-settings',
'import/index'
]),
'encode' => false,
],
//Info
[
'label' => '<span class="glyphicon glyphicon-stats"></span> Info',
'options' => ['class' => 'pull-right'],
'active' => in_array($route, [
'client/stats',
'client/survey-urls',
]),
'encode' => false,
'items' => [
[
'label' => '<span class="glyphicon glyphicon-stats"></span> Stats',
'url' => $getRoute('client/stats', 'client_id'),
'active' => in_array($route, ['client/stats',]),
'encode' => false,
'visible' => $mhmOrClientAdmin,
],
[
'label' => '<span class="glyphicon glyphicon-file"></span> Guides',
'url' => '/guides/' . $Client->hash,
'encode' => false,
'linkOptions' => [ 'target' => '_blank'],
'visible' => $Client->isFullOrUpgrading,
],
[
'label' => '<span class="glyphicon glyphicon-link"></span> Survey URLs',
'url' => $mhmUser ? ['client/survey-urls', 'client_id' => $Client->id] : ['client/survey-urls'],
'encode' => false,
],
],
],
//Settings
[
'label' => '<span class="glyphicon glyphicon-cog"></span> Account settings',
'options' => ['class' => 'pull-right'],
'active' => in_array($route, [
'client/anonymisation',
'contact/index',
'contact/update',
'contact/create',
'contact/delete',
'user/index',
'user/create-update',
]),
'encode' => false,
'items' => [
[
'label' => '<span class="glyphicon glyphicon-erase"></span> Anonymisation',
'url' => $getRoute('client/anonymisation', 'id'),
'active' => in_array($route, ['client/anonymisation']),
'encode' => false,
],
[
'label' => '<span class="glyphicon glyphicon-envelope"></span> Email List',
'url' => $getRoute('contact/index', 'client_id'),
'active' => in_array($route, [
'contact/index',
'contact/update',
'contact/create',
'contact/delete',
]),
'encode' => false,
],
[
'label' => '<span class="glyphicon glyphicon-user"></span> Users <span class="badge">'.count($Client->clientUsers).'</span>',
'url' => $getRoute('user/index', 'client_id'),
'active' => in_array($route, [
'user/index',
'user/create-update',
]),
'encode' => false,
'visible' => $mhmOrClientAdmin,
],
],
],
];
echo Nav::widget([
'options' => [
'class' => 'nav nav-pills',
'id'=>'nav-bar',
],
'items' => $items,
]);
?>
<style>
#nav-bar {
background-color: aliceblue
}
</style>
Hope this answer will help:
return $this->render('index', array(
'ImportForm' => $ImportForm,
'Client' => $Client
));
Focus on your Index action on ImportController. I think you forgot to pass that $Client to index.php.
Also, remove $Client= null; in your view file (index.php) above $this->title;
I am trying to use Yii2's conditional validator within DynamicModel clas, but the validator when is not working:
Controller
private function createFormModel(){
$model = new DynamicModel([
'indicador',
'departamento',
'mes'
]);
$model->addRule(['indicador'],'required',['message' => 'Este campo es obligatorio']);
$model->addRule(['departamento'], 'required', ['when' => function ($model) {
return $model->indicador == 'Semana';
}]);
return $model;
}
public function actionCuatrimestre()
{
$model = $this->createFormModel();
return $this->render('cuatrimestre',[
'model' => $model,
]);
}
Whether I select or not the "indicador" field which is a select field, the "departamento" field alwasys returns as required. I have algo try this way but with no results:
$model->addRule(['departamento'], 'required', ['when' => function ($model) {
return $model->indicador == 'Semana';
}], ['whenClient' => "function (attribute, value) {
return $('#indicador').val() == 'Semana';
}"]);
What I am missing here?
EDIT
My view code cuatrimestre.php
<?php $form = ActiveForm::begin(); ?>
<div class="form-group">
<?= $form->field($model, 'indicador')->widget(Select2::class, [
'options' => ['id'=>'indicador'],
'data' => ['Semana','Día','Resumen'],
]); ?>
</div>
<div class="form-group">
<?= $form->field($model, 'departamento')->widget(Select2::class, [
'options' => ['id'=>'departamento'],
'data' => Departamentos::getDepartamentosByUser(),
]); ?>
</div>
<div class="form-group">
<?= $form->field($model, 'curso')->widget(DepDrop::class, [
'type' => DepDrop::TYPE_SELECT2,
'options' => ['id' => 'curso-id'],
'select2Options' => ['pluginOptions' => ['allowClear' => true]],
'pluginOptions' => [
'depends' => ['departamento-id'],
'placeholder'=>'Seleccionar curso',
'url' => Url::to(['/campus-actividad/subcursos']),
'loadingText' => 'Cargando ...',
'initialize' => true,
]
]);?>
</div>
<div>
<?= Html::submitButton('Aplicar filtros', ['class' => 'btn btn-block btn-default']) ?>
<?php ActiveForm::end(); ?>
</div>
Recently I installed the multiSelect check box extension.
my _form.php looks like this:
<? = $ Form-> field ($ model_detail, 'product_id') ->
widget (MultiSelect :: className (),
['id' => "multiXX",
"options" => ['multiple' => "multiple"],
'data' => $ rows,
'attribute' => 'product_id',
'model' => $ models ,
"clientOptions" =>
[
"includeSelectAllOption" => true, 'numberDisplayed' => 2,
],
]);
How can I extract the data chosen by the user in actionCreate of anther model?
how can I get the options that the user selected?
(I tried the $_post[] and it didn't worked.)
this is the whole form:
div class="customer-order2-form">
<?php $form = ActiveForm::begin(['action' => ['create']]); ?>
<?= $form->field($model, 'customer_name')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'customer_phone')->widget(\yii\widgets\MaskedInput::className(),
[
'mask' => '999-9999999',
'clientOptions' => ['alias' => '972']
]) ?>
<?php /* $form->field($model, 'customer_phone')->textInput(['maxlength' => 255]) **/?>
<?= $form->field($model, 'order_date')->widget(
DatePicker::className(), [
'inline' => false,
// 'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
'clientOptions' => [
'autoclose' => true,
'format' => 'yyyy-m-d'
]
]);?>
<?php $model_detail = new OrderDetails2(); /* -------- כאן הוספתי נתונים ממודל
$rows=ArrayHelper::map(ProductFamily::find()->all(), 'id', 'name'); //--- אין צורך בשאילתא, עכשיו גם מציג את מה שנבחר למעלה
?>
<?= $form->field($model_detail, 'product_id')->widget(
MultiSelect::className(), [
'id'=>"multiXX",
"options" => ['multiple'=>"multiple"], // for the actual multiselect
'name' =>'multicheck',
'data' =>$rows,
'attribute' => 'product_id', // if preselected
'model' => $models,
"clientOptions" =>
[
"includeSelectAllOption" => true,
'numberDisplayed' => 2,
],
]);
?>
<?php
echo $form->field($model, 'description')->textarea(['rows' => 6]);
echo /*$form->field($model, 'totalprice')->textInput();*/
$form->field($model, 'totalprice')->widget(MaskMoney::classname(), [
'pluginOptions' => [
'prefix' => '₪ ',
'allowNegative' => false
]
]);
echo $form->field($model, 'status_id')->dropDownList(ArrayHelper::map(Status::find()->select('*')->all(), 'id', 'name'));
?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'יצירה' : 'עדכון', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
what i tried is saving to different table in DB with a default Array,
and it worked.
it looks like this:
public function actionCreate()
{
$model = new CustomerOrder2();
$model_details= new OrderDetails2();
if ($model->load(Yii::$app->request->post()) && $model->save())
{
if (isset($_POST['product_id'])){
$model_details->attributes = $_POST['product_id'];
$model_details->attributes=array();
echo
$model_details->attributes;
}
echo $_POST['description'];
$values = Array('1'=>'1','2'=>'2');
$model_details->attributes = $_POST['product_id'];
$array=$model_details->attributes;
//$data=OrderDetails2::->request->post();
//$values= Array(Yii::$app->request->post()['multiXX']);
//$values=Array($model_details->attributes);
foreach($values as $value)
{
$command = Yii::$app->db->createCommand();
$command->insert('order_details',array('Order_id'=>$model->id,
'product_id'=> $value,
'quantityOrdered'=> '1',
));
$command->execute();
}
return $this->redirect(['view', 'id' => $model->id]);
}
else {
return $this->render('create', [
'model' => $model,
]);
}
}
I am new to yii2 framework. I have created a controller,model and view. But i am getting not found error(404).
I have create the controller TestController.php, a view create.php and a model Test.php. I have try to run my project in particular controller that time im getting not found error message.
This is my controller page
The controller extends by Controller class. I've using alert boxes in controller page but i hasn't get in any alert.
class TestController extends Controller
{
namespace livefactory\modules\test\controllers;
public function actionCreate()
{
if(!Yii::$app->user->can('Test.Create')){
throw new NotFoundHttpException('You dont have permissions to view this page.');
}
$img = new ImageUpload();
$emailObj = new SendEmail;
$model = new Test;
return $this->render('create', [
'model' => $model,
]);
}
}
My model page
The model page defines all the variables used in the particular controller.
The table name is also defined.
namespace livefactory\models;
class Test extends \yii\db\ActiveRecord
{
/**
* #inheritdoc
*/
public static function tableName()
{
return 'tbl_test';
}
/**
* #inheritdoc
*/
public function rules()
{
return [
[['Name', 'Relationship', 'Age', 'Mail', 'Status'], 'required'],
[['Age'], 'integer'],
[['Name', 'Relationship', 'Mail', 'Status'], 'string', 'max' => 255]
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'Name' => Yii::t('app', 'Person Name'),
'Relationship' => Yii::t('app', 'Relationship'),
'Age' => Yii::t('app', 'Age'),
'Mail' => Yii::t('app', 'Mail'),
'Status' => Yii::t('app', 'Status'),
}
}
My view page
<?php
use yii\helpers\Html;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use kartik\widgets\ActiveForm;
use kartik\builder\Form;
use livefactory\models\Country;
use livefactory\models\State;
use livefactory\models\City;
use kartik\widgets\DepDrop;
use kartik\datecontrol\DateControl;
use livefactory\models\CustomerType;
/**
* #var yii\web\View $this
* #var common\models\Customer $model
*/
$this->title = Yii::t('app', 'Add Person', [
'modelClass' => 'Test',
]);
// $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Customers'), 'url' => ['index']];
// $this->params['breadcrumbs'][] = $this->title;
?>
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5><?= Html::encode($this->title) ?> <small class="m-l-sm"><?php echo Yii::t ( 'app', 'Enter Person Details' ); ?></small></h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="customer-form">
<?php
$form = ActiveForm::begin ( [
'type' => ActiveForm::TYPE_VERTICAL
] );?>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title"><?php echo Yii::t ( 'app', 'Person Details' ); ?></h3>
</div>
<div class="panel-body">
<?php
echo Form::widget ( [
'model' => $model,
'form' => $form,
'columns' => 4,
'attributes' => [
'Person Name' => [
'type' => Form::INPUT_TEXT,
'options' => [
'placeholder' => Yii::t ( 'app', 'Enter Person Name' ).'...',
'maxlength' => 255
],
'columnOptions' => [
'colspan' => 3
]
]
,
'Relationship' => [
'type' => Form::INPUT_TEXT,
'options' => [
'placeholder' => Yii::t ( 'app', 'Enter Relationship' ).'...',
'maxlength' => 255
],
'columnOptions' => [
'colspan' => 3
]
]
]
]
);
echo Form::widget ( [
'model' => $model,
'form' => $form,
'columns' => 3,
'attributes' => [
'Age' => [
'type' => Form::INPUT_TEXT,
'options' => [
'placeholder' => Yii::t ( 'app', 'Enter Age' ).'...',
'maxlength' => 255
]
],
'Mail' => [
'type' => Form::INPUT_TEXT,
'options' => [
'placeholder' => Yii::t ( 'app', 'Enter Mail' ).'...',
'maxlength' => 255
]
],
'Status' => [
'type' => Form::INPUT_TEXT,
'options' => [
'placeholder' => Yii::t ( 'app', 'Enter Status' ).'...',
'maxlength' => 255
]
]
]
] );
?>
</div></div>
<?php
// echo Html::submitButton ( $model->isNewRecord ? Yii::t ( 'app', 'Create' ) : Yii::t ( 'app', 'Update' ), [
// 'class' => $model->isNewRecord ? 'btn btn-success customer_submit' : 'btn btn-primary customer_submit'
// ] );
ActiveForm::end ();
?>
</div>
</div>
</div>
So I have created a simple search form, and created the query within my controller (I am aware this isn't the best way to do it and should be done in my model/search model however for the time being it will do).
I was wondering how can I add an option to my form within the two dropdown with the label All which if passed will mean that that part of the query isn't applied.
Below is my view
<?php $form = ActiveForm::begin(['id' => 'home-search','method' => 'post', 'action' => Url::to(['productitem/search'])]); ?>
<?= $form->field($productitem, 'name')->textInput(array('placeholder' => 'What are you looking for?'))->label(false) ?>
<?= $form->field($productitem, 'brand_id')->dropDownList(
ArrayHelper::map(ProductBrand::find()->all(),'id','name'),
['prompt'=>'Select Brand']
)->label(false) ?>
<?= $form->field($productitem, 'category_id')->dropDownList(
ArrayHelper::map(ProductCategory::find()->all(),'id','name'),
['prompt'=>'Select Department']
)->label(false) ?>
<div class="form-group search-button">
<button type="submit" class="btn btn-primary" name="login-button">Search <i class="fa fa-lg fa-arrow-circle-o-right"></i></button>
</div>
<?php ActiveForm::end(); ?>
Below is my controller/query
public function actionSearch()
{
$query = ProductItem::find()
->andFilterWhere(['like', 'name', $_POST['ProductItem']['name']])
->andFilterWhere(['in', 'brand_id', $_POST['ProductItem']['brand_id']])
->andFilterWhere(['in', 'category_id', $_POST['ProductItem']['category_id']]);
$dataProvider = new ActiveDataProvider([
'query' => $query
]);
return $this->render('search', [
'dataProvider' => $dataProvider,
]);
}
hope this will offer some reference.
<?= $form->field($model, 'categoryid1')->widget(Select2::className(), [
'id' => 'categoryid1',
'name' => 'categoryid1',
'data' => ArrayHelper::map(Category::getCategoryByPid(0), 'id', 'name'),
'options' => [
'placeholder' => 'choose first',
],
'pluginOptions' => [
'allowClear' => true
],
])->label('first') ?>
<?= $form->field($model, 'categoryid2')->widget(DepDrop::className(), [
'type' => DepDrop::TYPE_SELECT2,
'id' => 'categoryid2',
'name' => 'categoryid2',
'data' => $model->categoryid1 ? ArrayHelper::map(Category::getCategoryByPid($model->categoryid1), 'id', 'name') : [],
'pluginOptions' => [
'depends' => ['product-categoryid1'],
'placeholder' => 'choose second',
'url' => Url::to(['/category/second'])
]
])->label('second'); ?>
<?= $form->field($model, 'categoryid')->widget(DepDrop::className(), [
'type' => DepDrop::TYPE_SELECT2,
'data' => $model->categoryid2 ? ArrayHelper::map(Category::getCategoryByPid($model->categoryid2), 'id', 'name') : [],
'pluginOptions' => [
'depends' => ['product-categoryid1', 'product-categoryid2'],
'placeholder' => 'third',
'url' => Url::to(['/category/third'])
]
])->label('third'); ?>