\$('#person-form').submit(); }); \$('#person-form').on('submit', function(event) { \$.pjax.submit(event, '#person-debt'); return false; }); \$('#person-debt').on('pjax:complete', function() { setDebtFormHandlers(); }); JS; $this->registerJs($script, View::POS_READY); $personEngine = new Bloodhound(['name' => 'personEngine', 'clientOptions' => ['limit' => 10, 'datumTokenizer' => new \yii\web\JsExpression("Bloodhound.tokenizers.obj.whitespace('name')"), 'queryTokenizer' => new \yii\web\JsExpression("Bloodhound.tokenizers.whitespace"), 'remote' => ['url' => Url::to(['/api/autocomplete/person', 'query' => 'QRY']), 'wildcard' => 'QRY']]]); echo Html::beginForm([''], 'get', ['id' => 'person-form', 'autocomplete' => 'off']); echo Html::hiddenInput('id', isset($person) ? $person->person_id : null, ['id' => 'person-id']); echo TypeAhead::widget(['value' => isset($person) ? $person->fullName : null, 'id' => 'person-name', 'name' => 'person', 'options' => ['class' => 'form-control', 'type' => 'search', 'placeholder' => 'Введите ФИО', 'tabindex' => 4], 'engines' => [$personEngine], 'clientOptions' => ['highlight' => true, 'minLength' => 1], 'dataSets' => [['name' => 'street', 'displayKey' => 'value', 'source' => $personEngine->getAdapterScript()]]]); echo Html::endForm(); Pjax::begin(['id' => 'person-debt']); if (isset($person)) { $newItem = $this->render('_form_debt', ['model' => $newDebt]); if (empty($person->debts)) { echo Html::tag('div', $newItem, ['class' => 'row']); } else { echo ListView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $person->debts, 'pagination' => false]), 'layout' => "<div class=\"row\">" . $newItem . "{items}</div>\n", 'itemOptions' => ['class' => 'item'], 'itemView' => function ($model, $key, $index, $widget) { return $this->render('_form_debt', ['model' => $model]); }]); } } Pjax::end(); ?> <div>
echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo IconUpload::widget(['model' => $model, 'hiddenInputId' => '#tag-icon', 'uploadUrl' => Url::to(['/api/file/upload', 'fileparam' => 'icon', 'access-token' => Yii::$app->user->identity->access_token])]); ?> <?php echo $form->field($model, 'icon')->label(false)->hiddenInput(); ?> <?php echo $form->field($model, 'parent')->widget(TypeAhead::className(), ['options' => ['class' => 'form-control', 'placeholder' => '请搜索,选择上级,默认为顶级'], 'engines' => [$engine], 'clientOptions' => ['highlight' => true, 'minLength' => 1], 'clientEvents' => ['typeahead:selected' => 'function (event,obj) { console.log(obj); $("#tag-pid").val(obj.id); }'], 'dataSets' => [['name' => 'topic-tag', 'displayKey' => 'value', 'source' => $engine->getAdapterScript()]]]); ?> <?php echo $form->field($model, 'pid')->label(false)->hiddenInput(['value' => 0]); ?> <?php echo $form->field($model, 'about')->textarea(['maxlength' => true]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end();