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

Use kartik\datecontrol\DateControl as column type did not work. #215

Closed
soap opened this issue May 23, 2018 · 7 comments
Closed

Use kartik\datecontrol\DateControl as column type did not work. #215

soap opened this issue May 23, 2018 · 7 comments
Labels

Comments

@soap
Copy link

soap commented May 23, 2018

I have setup kartik's DateControl as TabularInput column, but it doesn't work. When looking at debug information I found that the control was placed with no index. Like this [ClassAttendant][enroll_date] instead of [ClassAttendant][0][enroll_date] .

There is no problem on display in View.

What I have done wrong? DatePicker as a column works fine but I have a problem saving date as integer. Any solution?
image

@soap
Copy link
Author

soap commented May 23, 2018

There is JavaScript error provided as below image.
image

@unclead
Copy link
Owner

unclead commented May 25, 2018

Provide an example of code to reproduce the bug. Without that nobody will help you

@soap
Copy link
Author

soap commented May 29, 2018

This is my view code.

<?php

use unclead\multipleinput\multipleInputColumn;
use yii\helpers\Url;
use yii\bootstrap\Html;
use yii\web\View;
use yii\web\JsExpression;
use yii\helpers\ArrayHelper;
use app\models\Student;

$formatJs = <<< 'JS'
var formatStudent = function (student) {
    if (student.loading) {
        return student.text;
    }
 var markup = 
'<div class="row">' + 
    '<div class="col-sm-6">' +
        '<img src="' + student.image_url + '" class="img-rounded" style="width:50px" />' +
        '<b style="margin-left:5px">' + student.name + '</b>' + 
    '</div>' +
    '<div class="col-sm-3">' + student.nick_name + '</div>' +
    '<div class="col-sm-3"><i class="fa fa-star"></i> ' + student.id + '</div>' +
'</div>';
    if (student.description) {
      markup += '<h5>' + student.description + '</h5>';
    }
    return '<div style="overflow:hidden;">' + markup + '</div>';
};
var formatStudentSelection = function (student) {
    return student.name || student.text;
}

JS;

// Register the formatting script
$this->registerJs($formatJs, View::POS_HEAD);

// script to parse the results into the format expected by Select2
$resultsJs = <<< JS
function  (data, params) {
    params.page = params.page || 1;
    return {
        results: data.items,
        pagination: {
            more: (params.page * 30) < data.total_count
        }
    };
}
JS;

?>
<?= \unclead\multipleinput\TabularInput::widget( [
    'id' => 'class-attendant',
    'models' => $modelsAttendant,
    'modelClass' => \app\models\ClassAttendantDateControl::class,
    'form' => $form,
    'min' => 0,
    'max' => 100,

    'columns' => [
        [
            'name' => 'id',
            'title' => 'ID',
            'enableError' => true,
            'type' => MultipleInputColumn::TYPE_HIDDEN_INPUT,
        ],
        [
            'name' => 'class_id',
            'title' => 'Class',
            'enableError' => true,
            'type' => MultipleInputColumn::TYPE_HIDDEN_INPUT,
            'defaultValue' => $modelClass->id
        ],
        [
            'name' => 'student_id',
            'title' => 'Student ID',
            'enableError' => true,
            'type' => \kartik\select2\Select2::class,

            'options' => [
                /*'initValueText' => function($data) {
                    return (string)$data->student->first_name;
                },*/
                'data' => ArrayHelper::map(Student::find()->select(['id', 'concat(first_name," ", last_name) as name'])->where([])->asArray()->all(), 'id', 'name'),
                'pluginOptions' => [
                    'allowClear' => true,
                    'minimumInputLength' => 2,
                    'ajax' => [
                        'url' => Url::to(['class/list-student']),
                        'dataType' => 'json',
                        'delay' => 250,
                        'data' => new JsExpression('function(params) { return {class_id: '.$modelClass->id.', q: params.term, page: params.page}; }'),
                        'processResults' => new JsExpression($resultsJs),
                        'cache' => false
                    ],
                    'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                    'templateResult' => new JsExpression('formatStudent'),
                    'templateSelection' => new JsExpression('formatStudentSelection'),
                ],
            ]
        ],
        [
            'name' => 'enroll_date',
            'title' => 'Enroll Date',
            'type' => \kartik\datecontrol\DateControl::className(),
            'options' => [
                'type' => \kartik\datecontrol\DateControl::FORMAT_DATE,
                'pluginOptions' => [
                    'autoclose' => true,
                    'format' => 'dd/mm/yyyy',
                    'todayHighlight' => true,
                ],
                'widgetOptions' => [
                    'type' => \kartik\date\DatePicker::TYPE_INPUT,
                ],

            ],
        ],
        [
            'name' => 'status',
            'title' => 'Is Active',
            'type' => \toxor88\switchery\Switchery::className(),
            'defaultValue' => 1,
            'options' => [
                //start point for widget parameters
                'options' => [
                        'label'=> null,
                ],
            ],
            'items' => [
                1 => 'Yes',
                0 => 'No'
            ]
        ]
    ]
]);
?>

@vitorarantes
Copy link

just tested it, and I get the same problem here using DateControl.

@unclead
Copy link
Owner

unclead commented Aug 5, 2018

have anyone tried to find the problem and fix it?
I mean if you faced the problem and interested in a solving it you can spent time and help to find a solution.

Unfortunately I don't have time to solve such issues (I haven't used yii2 for a long time). But we brought up a good community around the widget and I hope somebody will help us to solve this issue

@unclead unclead added the bug label Oct 2, 2018
unclead pushed a commit that referenced this issue Oct 6, 2018
@unclead
Copy link
Owner

unclead commented Oct 6, 2018

fixed via ae0f7f9
you can update to latest version (master) to ensure that issue is gone

@unclead unclead closed this as completed Oct 6, 2018
@Legion112
Copy link

@unclead
I didn't expect you will fix this bug.
Wanna say thank you. DateControl really so useful. 🥇

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

4 participants