kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
556 stars 303 forks source link

EditableInput / afterInput and beforeInput are failing #98

Closed ItsReddi closed 10 years ago

ItsReddi commented 10 years ago

hi i copied your configuration on demo site for the first field:

[
                'class' => 'kartik\grid\EditableColumn',
                'attribute' => 'number',
                'vAlign' => 'middle',
                'headerOptions' => [
                    'class' => 'kv-sticky-column'
                ],
                'contentOptions' => [
                    'class' => 'kv-sticky-column'
                ],
                'editableOptions'=>function ($model, $key, $index) {
                    return [
                        'header'=>'Name', 
                        'size'=>'md',
                        'afterInput'=>function ($form, $widget) use ($model, $index) {
                            echo $form->field($model, "[{$index}]color")->widget(\kartik\widgets\ColorInput::classname(), [
                                'showDefaultPalette' => false,
                                'pluginOptions' => [
                                    'showPalette' => true,
                                    'showPaletteOnly' => true,
                                    'showSelectionPalette' => true,
                                    'showAlpha' => false,
                                    'allowEmpty' => false,
                                    'preferredFormat' => 'name',
                                    'palette' => [
                                        [
                                            "white", "black", "grey", "silver", "gold", "brown", 
                                        ],
                                        [
                                            "red", "orange", "yellow", "indigo", "maroon", "pink"
                                        ],
                                        [
                                            "blue", "green", "violet", "cyan", "magenta", "purple", 
                                        ],
                                    ],
                                ],
                            ]);
                        }
                    ];
                }
            ],
        ];

i got an error it seems that the closure isnt executed?: bildschirmfoto 2014-10-21 um 12 46 44

im using the latest widgets / grids an so on.

kartik-v commented 10 years ago

Not sure why... hope your PHP version is correct.. :-).

Anyway, a small change -- you may try changing the echo to return in your Closure (not that should matter much though):

'afterInput' => function ($form, $widget) use ($model, $index) {
    return $form->field($model, "[{$index}]color")->widget(\kartik\widgets\ColorInput::classname(), [
    ...
ItsReddi commented 10 years ago

PHP 5.5.11

doesnt matter return or echo. smae error even with

function () {
    echo "test"; // or return "test";
   }
kartik-v commented 10 years ago

I am not able to reproduce this. If you can debug and let know it would be helpful.

ItsReddi commented 10 years ago

hmm just for knowledge... where do you execute the anonymous function? or is it some yii magic? i can only find the. (there is no executing?)

 if ($this->afterInput !== null) {
            echo $this->afterInput;
        }

if i change the code to: (executing the anonymous function it works)

        if ($this->afterInput !== null) {
            $tmp = $this->afterInput;
            echo $tmp();
        }
ItsReddi commented 10 years ago

there is no callUserFunc or anything else.

kartik-v commented 10 years ago

The validation is done in the Editable extension as seen here. I hope you have the updated code for yii2-editable.

ItsReddi commented 10 years ago

hmm strange. ok i dont have the right version! but im updating every day with following composer settings "minimum-stability": "dev", "require": { "php": ">=5.4.0", "yiisoft/yii2": "2.0.*", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*", "schmunk42/yii2-giiant":"*", "reddi/yii2-ar-softdelete-behavior":"1.0.*", "kartik-v/yii2-widgets":"*", "kartik-v/yii2-grid":"*", "kartik-v/yii2-detail-view": "*", "bariew/yii2-rbac-cms-module": "*", "kartik-v/yii2-builder": "*", "kartik-v/yii2-slider": "*", "kartik-v/yii2-popover-x": "*", .... },

kartik-v commented 10 years ago

Follow this webtip when composer is behaving funny and not updating.

ItsReddi commented 10 years ago

found it... i set the prefer-stable to true.. i thought you dont have any stable releases at the moment ^^ thanks...