<?php use yii\bootstrap\ActiveForm; use unclead\multipleinput\TabularInput; use yii\helpers\Html; use unclead\multipleinput\examples\models\Item; use unclead\multipleinput\TabularColumn; /* @var $this \yii\web\View */ /* @var $models Item[] */ ?> <?php $form = \yii\bootstrap\ActiveForm::begin(['id' => 'tabular-form', 'options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo TabularInput::widget(['models' => $models, 'attributeOptions' => ['enableAjaxValidation' => true, 'enableClientValidation' => false, 'validateOnChange' => false, 'validateOnSubmit' => true, 'validateOnBlur' => false], 'form' => $form, 'columns' => [['name' => 'id', 'type' => TabularColumn::TYPE_HIDDEN_INPUT], ['name' => 'title', 'title' => 'Title', 'type' => TabularColumn::TYPE_TEXT_INPUT, 'attributeOptions' => ['enableClientValidation' => true, 'validateOnChange' => true], 'defaultValue' => 'Test', 'enableError' => true], ['name' => 'description', 'title' => 'Description'], ['name' => 'date', 'type' => \kartik\date\DatePicker::className(), 'title' => 'Day', 'options' => ['pluginOptions' => ['format' => 'dd.mm.yyyy', 'todayHighlight' => true]], 'headerOptions' => ['style' => 'width: 250px;', 'class' => 'day-css-class']]]]); ?> <?php echo Html::submitButton('Update', ['class' => 'btn btn-success']); ActiveForm::end();
/** * Register script. * * @throws \yii\base\InvalidParamException */ protected function registerAssets() { $view = $this->context->getView(); MultipleInputAsset::register($view); $view = $this->context->getView(); $jsBefore = []; if (is_array($view->js) && array_key_exists(View::POS_READY, $view->js)) { foreach ($view->js[View::POS_READY] as $key => $js) { $jsBefore[$key] = $js; } } $template = $this->prepareTemplate(); $jsTemplates = []; if (is_array($view->js) && array_key_exists(View::POS_READY, $view->js)) { foreach ($view->js[View::POS_READY] as $key => $js) { if (array_key_exists($key, $jsBefore)) { continue; } $jsTemplates[$key] = $js; unset($view->js[View::POS_READY][$key]); } } $options = Json::encode(['id' => $this->id, 'template' => $template, 'jsTemplates' => $jsTemplates, 'max' => $this->max, 'min' => $this->min, 'attributes' => $this->prepareJsAttributes(), 'indexPlaceholder' => $this->getIndexPlaceholder()]); $js = "jQuery('#{$this->id}').multipleInput({$options});"; $view->registerJs($js); }