/** * Renders the cell content. * * @param string $value * @param int|null $index * @return string * @throws InvalidConfigException */ public function renderCellContent($value, $index) { $type = $this->type; $name = $this->widget->getElementName($this->name, $index); $options = $this->options; $options['id'] = $this->widget->getElementId($this->name, $index); Html::addCssClass($options, 'form-control'); switch ($this->type) { case self::TYPE_HIDDEN_INPUT: $input = Html::hiddenInput($name, $value, $options); break; case self::TYPE_DROPDOWN: case self::TYPE_LISTBOX: case self::TYPE_CHECKBOX_LIST: case self::TYPE_RADIO_LIST: $input = Html::$type($name, $value, $this->items, $options); break; case self::TYPE_STATIC: $input = Html::tag('p', $value, ['class' => 'form-control-static']); break; default: if (method_exists('yii\\helpers\\Html', $type)) { $input = Html::$type($name, $value, $options); } elseif (class_exists($type) && method_exists($type, 'widget')) { $input = $type::widget(array_merge($options, ['name' => $name, 'value' => $value])); } else { throw new InvalidConfigException("Invalid column type '{$type}'"); } } if ($this->isHiddenInput()) { return $input; } $input = Html::tag('div', $input, ['class' => 'form-group field-' . $options['id']]); return Html::tag('td', $input, ['class' => 'list-cell__' . $this->name]); }
/** * Renders the cell content. * * @param string $value * @param int|null $index * @return string * @throws InvalidConfigException */ public function renderCellContent($value, $index) { $name = $this->widget->getElementName($this->name, $index); $options = $this->options; $options['id'] = $this->widget->getElementId($this->name, $index); $input = $this->renderInput($name, $value, $options); if ($this->isHiddenInput()) { return $input; } $hasError = false; if ($this->enableError) { $attribute = $this->widget->attribute . $this->widget->getElementName($this->name, $index, false); $error = $this->widget->model->getFirstError($attribute); $hasError = !empty($error); $input .= "\n" . $this->renderError($error); } $wrapperOptions = ['class' => 'form-group field-' . $options['id']]; if ($hasError) { Html::addCssClass($wrapperOptions, 'has-error'); } $input = Html::tag('div', $input, $wrapperOptions); return Html::tag('td', $input, ['class' => 'list-cell__' . $this->name]); }
/** * Run widget. */ public function run() { $this->jsOptions['afterAddRow'] = isset($this->jsOptions['afterAddRow']) ? $this->jsOptions['afterAddRow'] : new JsExpression('function (event) { yii.validation.multipleModel.addRow.call(this, arguments); }'); $this->jsOptions['afterDeleteRow'] = isset($this->jsOptions['afterDeleteRow']) ? $this->jsOptions['afterDeleteRow'] : new JsExpression('function (event) { yii.validation.multipleModel.addRow.call(this, arguments); }'); foreach ($this->jsOptions as $_name => $func) { $this->view->registerJs("\$('#{$this->options['id']}').on('{$_name}', {$func});"); } return parent::run(); }
<?php echo $form->field($model, 'first_name')->textInput(); ?> <?php echo $form->field($model, 'middle_name')->textInput(); ?> <?php echo $form->field($model, 'last_name')->textInput(); ?> <?php echo $form->field($model, 'authAssignments')->widget(MultipleInput::className(), ['min' => 1, 'limit' => 10, 'columns' => [['name' => 'item_name', 'type' => 'dropDownList', 'defaultValue' => 'user', 'items' => ArrayHelper::map(\common\models\AuthItem::find()->all(), 'name', 'description')]]]); ?> <?php $tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL); $list = array(); foreach (Yii::$app->params['timezones'] as $key => $tz) { $list[$tz] = $key; } ?> <?php echo $form->field($model, 'timezone')->dropDownList($list); ?> <div class="form-group">
/* @var $this \yii\web\View */ /* @var $model ExampleModel */ ?> <?php $form = ActiveForm::begin(['enableAjaxValidation' => true, 'enableClientValidation' => false, 'validateOnChange' => false, 'validateOnSubmit' => true, 'validateOnBlur' => false]); ?> <h3>Single column</h3> <?php echo $form->field($model, 'emails')->widget(MultipleInput::className(), ['limit' => 5])->label(false); ?> <h3>Multiple columns</h3> <?php echo $form->field($model, 'schedule')->widget(MultipleInput::className(), ['id' => 'schedule-wrapper', 'limit' => 4, 'columns' => [['name' => 'user_id', 'type' => MultipleInputColumn::TYPE_DROPDOWN, 'enableError' => true, 'title' => 'User', 'defaultValue' => 33, 'items' => [31 => 'item 31', 32 => 'item 32', 33 => 'item 33', 34 => 'item 34', 35 => 'item 35', 36 => 'item 36']], ['name' => 'day', 'type' => DatePicker::className(), 'title' => 'Day', 'value' => function ($data) { return $data['day']; }, 'items' => ['0' => 'Saturday', '1' => 'Monday'], 'options' => ['pluginOptions' => ['format' => 'dd.mm.yyyy', 'todayHighlight' => true]], 'headerOptions' => ['style' => 'width: 250px;', 'class' => 'day-css-class']], ['name' => 'priority', 'title' => 'Priority', 'defaultValue' => 1, 'enableError' => true, 'options' => ['class' => 'input-priority']], ['name' => 'comment', 'type' => MultipleInputColumn::TYPE_STATIC, 'value' => function ($data) { return Html::tag('span', 'static content', ['class' => 'label label-info']); }, 'headerOptions' => ['style' => 'width: 70px;']], ['type' => MultipleInputColumn::TYPE_CHECKBOX_LIST, 'name' => 'enable', 'headerOptions' => ['style' => 'width: 80px;'], 'items' => [1 => 'Test 1', 2 => 'Test 2', 3 => 'Test 3', 4 => 'Test 4'], 'options' => ['unselect' => 2]]]]); ?> <?php echo Html::submitButton('Update', ['class' => 'btn btn-success']); ActiveForm::end(); ?> <?php $js = <<<JS \$('#schedule-wrapper').on('afterInit', function(){
/* @var $this \yii\web\View */ /* @var $model ExampleModel */ ?> <?php $form = ActiveForm::begin(['enableAjaxValidation' => true, 'enableClientValidation' => false, 'validateOnChange' => false, 'validateOnSubmit' => true, 'validateOnBlur' => false]); ?> <h3>Single column</h3> <?php echo $form->field($model, 'emails')->widget(MultipleInput::className(), ['limit' => 6, 'allowEmptyList' => false, 'enableGuessTitle' => true, 'min' => 2, 'addButtonPosition' => MultipleInput::POS_HEADER])->label(false); ?> <h3>Multiple columns</h3> <?php echo $form->field($model, 'schedule')->widget(MultipleInput::className(), ['limit' => 4, 'allowEmptyList' => true, 'rowOptions' => function ($model) { $options = []; if ($model['priority'] > 1) { $options['class'] = 'danger'; } return $options; }, 'columns' => [['name' => 'user_id', 'type' => MultipleInputColumn::TYPE_DROPDOWN, 'enableError' => true, 'title' => 'User', 'defaultValue' => 33, 'items' => [31 => 'item 31', 32 => 'item 32', 33 => 'item 33', 34 => 'item 34', 35 => 'item 35', 36 => 'item 36']], ['name' => 'day', 'type' => DatePicker::className(), 'title' => 'Day', 'value' => function ($data) { return $data['day']; }, 'items' => ['0' => 'Saturday', '1' => 'Monday'], 'options' => ['pluginOptions' => ['format' => 'dd.mm.yyyy', 'todayHighlight' => true]], 'headerOptions' => ['style' => 'width: 250px;', 'class' => 'day-css-class']], ['name' => 'priority', 'title' => 'Priority', 'defaultValue' => 1, 'enableError' => true, 'options' => ['class' => 'input-priority']], ['name' => 'comment', 'type' => MultipleInputColumn::TYPE_STATIC, 'value' => function ($data) { return Html::tag('span', 'static content', ['class' => 'label label-info']); }, 'headerOptions' => ['style' => 'width: 70px;']], ['type' => MultipleInputColumn::TYPE_CHECKBOX_LIST, 'name' => 'enable', 'headerOptions' => ['style' => 'width: 80px;'], 'items' => [1 => 'Test 1', 2 => 'Test 2', 3 => 'Test 3', 4 => 'Test 4'], 'options' => ['unselect' => 2]]]]); ?> <?php echo Html::submitButton('Update', ['class' => 'btn btn-success']); ActiveForm::end();
<?php echo $form->field($model, 'phone'); ?> <?php $studentsList = Student::find()->select(['id', 'name as text'])->where(['id' => $model->students_list])->orderBy('text')->asArray()->all(); $data = []; $studentsListIdsByName = []; foreach ($studentsList as $student) { $data[$student['id']] = $student; $studentsListIdsByName[] = $student['id']; } $model->students_list = $studentsListIdsByName; $data = Json::encode($data); echo $form->field($model, 'students_list')->widget(MultipleInput::className(), ['allowEmptyList' => true, 'columns' => [['name' => 'students_list', 'type' => Select2::className(), 'options' => ['pluginOptions' => ['minimumInputLength' => 3, 'ajax' => ['url' => Url::to(['student/list']), 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }'), 'results' => new JsExpression(' function (data) { return { results: $.map(data, function (item) { return { text: item.name, id: item.id } }) }; } ')], 'initSelection' => new JsExpression(' function (element, callback) { var id = element.val(); if(id) {
<?php echo $form->field($model, 'description')->textarea(['maxlength' => 1500, 'class' => 'mlang', 'id' => 'ckeditor']) ?> <?php $projectTypes = \common\models\ProjectsType::getTypeLabels(); if (sizeof($projectTypes) > 0) { ?> <div class="form-group col-md-6"> <?php echo $form->field($model, 'type_id')->dropDownList($projectTypes); ?> </div> <? } echo Html::a(Yii::t('backend', 'Edit type'), 'javascript: void(0);', ['class' => 'btn edit-children']); ?> <div class="form-group col-md-6 hidden edit-children-block"> <?php echo $form->field($model, 'types')->widget(MultipleInput::className(), [ 'columns' => [ [ 'name' => 'id', 'type' => 'hiddenInput' ], [ 'name' => 'active', 'type' => 'checkbox', 'headerOptions' => [ 'width' => '20px', ], 'defaultValue' => '1' ], [
?> <div class="area-personal-form"> <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'area_id')->dropDownList( ArrayHelper::map( Areas::find()->all(), 'id', 'name' ), array('prompt' => "")) ?> <?php if($model->isNewRecord){ ?> <?= $form->field($model, 'usersToAssing')->widget(MultipleInput::className(), [ 'limit' => 100, 'allowEmptyList' => false, 'columns'=> [ [ 'name' => 'usersToAssing', 'type' => MultipleInputColumn::TYPE_DROPDOWN, 'items'=>ArrayHelper::map( User::find()->all(), 'id', 'first_name' ), ] ]]) ?> <?php }else{ ?>
<?php use yii\bootstrap\ActiveForm; use unclead\widgets\MultipleInput; use unclead\widgets\examples\models\ExampleModel; use yii\helpers\Html; // Note: You have to install https://github.com/kartik-v/yii2-widget-datepicker for correct work an example use kartik\date\DatePicker; /* @var $this \yii\base\View */ /* @var $model ExampleModel */ ?> <?php $form = ActiveForm::begin(['enableAjaxValidation' => true, 'enableClientValidation' => false, 'validateOnChange' => false, 'validateOnSubmit' => true, 'validateOnBlur' => false]); ?> <h3>Single column</h3> <?php echo $form->field($model, 'emails')->widget(MultipleInput::className(), ['limit' => 5])->label(false); ?> <h3>Multiple columns</h3> <?php echo $form->field($model, 'schedule')->widget(MultipleInput::className(), ['limit' => 4, 'columns' => [['name' => 'user_id', 'type' => 'dropDownList', 'title' => 'User', 'defaultValue' => 1, 'items' => [1 => 'User 1', 2 => 'User 2']], ['name' => 'day', 'type' => DatePicker::className(), 'title' => 'Day', 'value' => function ($data) { return $data['day']; }, 'items' => ['0' => 'Saturday', '1' => 'Monday'], 'options' => ['pluginOptions' => ['format' => 'dd.mm.yyyy', 'todayHighlight' => true]], 'headerOptions' => ['style' => 'width: 250px;', 'class' => 'day-css-class']], ['name' => 'priority', 'title' => 'Priority', 'options' => ['class' => 'input-priority']], ['name' => 'comment', 'type' => 'static', 'value' => function ($data) { return Html::tag('span', 'static content', ['class' => 'label label-info']); }, 'headerOptions' => ['style' => 'width: 70px;']]]]); echo Html::submitButton('Update', ['class' => 'btn btn-success']); ActiveForm::end();
<?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'text')->widget(MarkdownEditor::className(), MdEditorHelp::getMdParamsWithMath()); ?> <?php echo $form->field($model, 'test')->checkbox(); ?> <?php echo $form->field($model, 'exerciseTests')->widget(MultipleInput::className(), ['addButtonPosition' => MultipleInput::POS_HEADER, 'min' => 0, 'columns' => [['name' => 'id', 'type' => 'hiddenInput'], ['name' => 'value', 'type' => 'textInput', 'title' => 'Ответ'], ['name' => 'istrue', 'type' => 'checkbox', 'title' => 'Правильный']]]); //->label(''); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Обновить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
echo $form->field($model, 'emails')->widget(\unclead\widgets\MultipleInput::className(), ['limit' => 6, 'allowEmptyList' => false, 'enableGuessTitle' => true, 'min' => 2, 'addButtonPosition' => \unclead\widgets\MultipleInput::POS_HEADER])->label(false); //echo $form->field($model, 'list')->widget(Select2::classname(), [ // 'data' => \app\models\TestModel::getTestDataList(), // 'language' => 'de', // 'options' => ['placeholder' => 'Select a state ...', 'multiple' => true], // 'pluginOptions' => [ // 'allowClear' => true // ], //]); ?> <h3>Multiple columns</h3> <?php echo $form->field($model, 'schedule')->widget(MultipleInput::className(), ['limit' => 4, 'allowEmptyList' => true, 'columns' => [['name' => 'list', 'type' => Select2::className(), 'title' => 'select2', 'options' => ['pluginOptions' => ['allowClear' => true]], 'defaultValue' => '', 'items' => \app\models\TestModel::getTestDataList()], ['name' => 'priority', 'title' => 'Priority', 'defaultValue' => 1, 'enableError' => true, 'options' => ['class' => 'input-priority']], ['name' => 'comment', 'type' => MultipleInputColumn::TYPE_STATIC, 'value' => function ($data) { return Html::tag('span', 'static content', ['class' => 'label label-info']); }, 'headerOptions' => ['style' => 'width: 70px;']], ['type' => MultipleInputColumn::TYPE_CHECKBOX_LIST, 'name' => 'enable', 'headerOptions' => ['style' => 'width: 80px;'], 'items' => [1 => 'Test 1', 2 => 'Test 2', 3 => 'Test 3', 4 => 'Test 4'], 'options' => ['unselect' => 2]]]]); ?> <?php echo Html::submitButton('Update', ['class' => 'btn btn-success']); ActiveForm::end(); ?> <?php $js = <<<JS \$('#examplemodel-schedule').on('afterInit', function(){ console.log('calls on after initialization event'); }).on('beforeAddRow', function(e) {
?> <hr/> <?php echo $form->errorSummary($model); ?> <?php echo $form->field($model, 'key')->textInput(['maxlength' => 1024]); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 512]); ?> <?php echo $form->field($model, 'items')->widget(MultipleInput::className(), ['columns' => [['name' => 'id', 'type' => 'hiddenInput'], ['name' => 'active', 'type' => 'checkbox', 'headerOptions' => ['width' => '20px'], 'defaultValue' => '1'], ['name' => 'name', 'title' => 'Пункт меню', 'value' => function ($data) { return $data->name; }, 'options' => ['class' => 'mlang']], ['name' => 'url', 'title' => 'Ссылка', 'value' => function ($data) { return $data->url; }, 'options' => ['class' => 'mlang']], ['name' => 'sort', 'title' => 'Сортировка', 'headerOptions' => ['width' => '100px'], 'defaultValue' => '500']]])->label(false); ?> <?php echo $form->field($model, 'status')->checkbox(); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> <?php
protected function collectJsTemplates($except = []) { $view = $this->context->getView(); $output = []; 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, $except)) { continue; } if (preg_match('/^[^{]+{multiple-index}.*$/m', $js) === 1) { $output[$key] = $js; unset($view->js[View::POS_READY][$key]); } } } return $output; }
$semesterList = $model->group_id ? ArrayHelper::map(GroupSemesters::find()->where(['group_id' => $model->group_id])->all(), 'id', 'semester_number') : []; if ($semesterList != []) { foreach ($semesterList as $key => $ar) { $semesterList[$key] = $ar . " - (" . Yii::$app->formatter->asDate(GroupSemesters::findOne($key)->begin_date) . ':' . Yii::$app->formatter->asDate(GroupSemesters::findOne($key)->end_date) . ')'; } } ?> <div class="group-has-discipline-form"> <?php $form = ActiveForm::begin(['id' => 'project-form', 'enableAjaxValidation' => true]); ?> <?php echo $form->field($model, 'teacherHasDiscipline')->widget(MultipleInput::className(), ['min' => 1, 'columns' => [['name' => 'teacher_id', 'type' => 'dropDownList', 'defaultValue' => 1, 'items' => ArrayHelper::map(\common\models\Teacher::find()->all(), 'id', 'user.fullname')]]]); ?> <?php echo $form->field($model, 'discipline_id')->dropDownList(ArrayHelper::map(Discipline::find()->all(), 'id', 'name')); ?> <?php echo $model->isNewRecord ? $form->field($model, 'group_id')->dropDownList(ArrayHelper::map(Group::find()->all(), 'id', 'name'), ['prompt' => '-Группа-', 'onchange' => ' $.post( "' . Yii::$app->urlManager->createUrl('group-has-discipline/semlist?id=') . '"+$(this).val(), function( data ) { $( "select#grouphasdiscipline-semester_id" ).html( data ); }); ', 'class' => 'form-control']) : ""; ?> <?php