johnitvn / yii2-ajaxcrud

Gii CRUD template for Single Page Ajax Administration for yii2
100 stars 114 forks source link

Widgets in crate modals #35

Closed aaron-cardenas closed 8 years ago

aaron-cardenas commented 9 years ago

Hi, i'm using karik widgets in the create forms. If i go directly to the create action all widgets work as expected, but if i click the add button in the gridview and the create form loads in the corresponding modal, the form loads ok but widget dont work. It isn't loading assets for de widgets.

To solve this, simply change the method renderPartial() for renderAjax() for the sections marked as "Process for ajax request" in src\generators\default\controller.php

suckkay commented 8 years ago

yeah i need this too, i hope next developing will support using another plugin like select2 , cke editor , timepicker and else

example when i using select2 the dropdown were hidden, and ckeditor not showing anthings only a text field, good luck

drsdre commented 8 years ago

Pull request https://github.com/johnitvn/yii2-ajaxcrud/pull/37 has just been posted including this fix.

suckkay commented 8 years ago

but in update not woriking . i try to render with ajax in ajaxcrud controller but still not working.

please check it again.

TurningTide commented 8 years ago

just use renderAjax except of renderPartial in controller actions.

suckkay commented 8 years ago

thanks :)

hyquoccuong commented 4 years ago

In conftroller and middle file we need to use renderAjax

                    'title' => "Create new App User",
                    'content' => $this->renderAjax('create', [
                        'model' => $model,
                    ]),
                    'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) .
                        Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])
                ];```

In create.php

```<div class="app-user-create">
    <?php if (Yii::$app->request->isAjax) { ?>
        <?= $this->renderAjax('_form', [
            'model' => $model,
        ]) ?>
    <?php } else { ?>
        <?= $this->render('_form', [
            'model' => $model,
        ]) ?>
    <?php } ?>

</div>```

And in _form.php (form view) we can use kartik widgets properly

<?= $form->field($model, 'country')->widget(\kartik\widgets\Select2::className(), [ 'data' => backend\modules\app\models\AppUser::lookupData('system_country', 'country_name', 'country_name'), 'options' => [ 'multiple' => false, 'prompt' => 'Select Country' ], 'pluginOptions' => [ 'allowClear' => true, 'tags' => true ] ]) ?>