Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabularInput not working in bootstrap modal. #58

Closed
hirenbhut93 opened this issue Feb 12, 2016 · 7 comments
Closed

TabularInput not working in bootstrap modal. #58

hirenbhut93 opened this issue Feb 12, 2016 · 7 comments
Assignees
Labels

Comments

@hirenbhut93
Copy link
Contributor

I implement TabularInput widget in bootstrap modal but is not working Add More button and ajax validation.Please check this issue.

@unclead
Copy link
Owner

unclead commented Feb 12, 2016

@hirenbhut93 Can you provide an example of code to reproduce an issue

@unclead unclead added the bug label Feb 12, 2016
@hirenbhut93
Copy link
Contributor Author

My View Code

<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>

<?php $form = ActiveForm::begin([
    'id' => 'multi-input',
]); ?>

    <?= unclead\widgets\TabularInput::widget([
        'models' => $models,
        'addButtonPosition' => unclead\widgets\MultipleInput::POS_HEADER,
        'addButtonOptions' => [
            'class' => 'btn btn-success', 
            'label' => '<i class="glyphicon glyphicon-plus"></i> Add More'
        ],
        'removeButtonOptions' => [
            'class' => 'btn btn-danger', 
            'label' => '<i class="glyphicon glyphicon-remove"></i> Remove'
        ],
        'allowEmptyList' => false,
        'attributeOptions' => [
            'enableAjaxValidation' => true,
            'enableClientValidation' => false,
            'validateOnChange' => false,
            'validateOnSubmit' => true,
            'validateOnBlur' => false,
        ],
        'columns' => [
            [
                'name'  => 'egl_name',
                'title' => $models[0]->getAttributeLabel('egl_name'),
                'enableError' => true,
            ],
            [
                'name'  => 'egl_min_marks',
                'title' => $models[0]->getAttributeLabel('egl_min_marks'),
                'enableError' => true,
            ],
            [
                'name'  => 'egl_max_marks',
                'title' => $models[0]->getAttributeLabel('egl_max_marks'),
                'enableError' => true,
            ],
            [
                'name'  => 'egl_point',
                'title' => $models[0]->getAttributeLabel('egl_point'),
                'enableError' => true,
            ],
            [
                'name'  => 'egl_level',
                'title' => $models[0]->getAttributeLabel('egl_level'),
                'type'  => 'radioList',
                'enableError' => true,
                'items' => $models[0]->getGradeLevelList(),
            ],
        ],
    ]) ?>

    <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-primary' : 'btn btn-info']) ?>

<?php ActiveForm::end(); ?>

My Controller Action

public function actionCreate()
{
    $esModel = new DemoSingle();
    $models = [new DemoMulti()]; 

    if ($esModel->load(Yii::$app->request->post()) && $eglData = Yii::$app->request->post('DemoMulti', [])) {
        foreach (array_keys($eglData) as $index) {
            $models[$index] = new DemoMulti();
        }

        if (Model::loadMultiple($models, Yii::$app->request->post()) && Yii::$app->request->isAjax) {
            \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
            return \yii\widgets\ActiveForm::validateMultiple($models);
        }

        if ($esModel->save()) {
            foreach ($models as $single) {
                // my code
            }
        } 
    } elseif(Yii::$app->request->isAjax) {
        return $this->renderAjax('create', [
            'esModel' => $esModel,
            'models' => $models
        ]);
    }

    return $this->render('create', [
        'esModel' => $esModel,
        'models' => $models,
    ]);
}

Note

This code without bootstrap modal work perfect
Your MultipleInput widget is work perfectly in bootstrap modal but TabularInput is not work.

@unclead
Copy link
Owner

unclead commented Feb 12, 2016

I have tried to reproduce and for me everything works correctly.
See my gist https://gist.github.com/unclead/bb4edad36ee5767facb7
If you try to use widget in other way please provide the code snippet which can me help to understand how you are using TabularInput with Modal
Also it can be usefull if you make a screenshot of Console tab in chrome dev tool. Probably i have some js errors there

@hirenbhut93
Copy link
Contributor Author

@unclead Your given code is work for Add More and Remove button in Bootstrap Modal but Ajax validation not work in my first row. when i added more row at time other row validation successfully.

Note:

I call Bootstrap Modal using load() method below jquery.
Ajax validation is not work in Radio button for me with or without modal.
No JS Errors produce in my browser Console.

My button code like this

<?= Html::a('<span class="glyphicon glyphicon-plus-sign"></span> Create New', ['create'], ['class' => 'btn btn-default link-modal']) ?>

My jquery code like this

jQuery(document).on('ready pjax:success', function() {
    $('.link-modal').click(function(e) {
        e.preventDefault();
        $('#my-modal').modal('show').find('.modal-content').load($(this).attr('href'));
    });
});

@unclead unclead self-assigned this Feb 22, 2016
@unclead
Copy link
Owner

unclead commented Feb 27, 2016

I don't know whether i have reproduced this issue correctly or not, but i found the following. When you get TabularInput via ajax you must specify an id for widget

    <?= unclead\widgets\TabularInput::widget([
        'id' => 'some-id
        'models' => $models,

otherwise the widget will get random ID and it can be the same as id of others elements on the page.
In my case it was id w0 and the page has already contained Nav widget with the same ID that is why TabularInput has not been initialized in correct way and nothing has worked.

But after i specified id the widget become to work correct (http://prntscr.com/a8ikyc)

@hirenbhut93
Copy link
Contributor Author

@unclead thanks Ajax Validation and Add More Problem resolved but Ajax validation is not work in Radio button for me with or without modal.

@unclead
Copy link
Owner

unclead commented Mar 7, 2016

You are right. There is a bug with validation of this types of input. I found the reason but i need a time to fix it. I created separate issue #64

This issue is solved and i close it.

@unclead unclead closed this as completed Mar 7, 2016
unclead added a commit that referenced this issue May 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants