kartik-v/yii2-editable

`htmlEncode` and multi-select $input

Closed this issue · 7 comments

Hi.
$input.val() may return array or null (if no options selected), in case of the $input is a multi-select.
It breaks htmlEncode method which expects that data is either an object or a string.
https://github.com/kartik-v/yii2-editable/blob/master/assets/js/editable.js#L59

My case:

  1. I have editable select2 with multiple option
  2. when I unselect all options and submit, my AJAX return empty string - data.output == ''
  3. htmlEncode fire with $input.val() == null and crash

Hello,
I have same problem, but with different case. I'm using kartik-v/yii2-gridview with EditableColumn. But, the javascript used is from kartik-v/yii2-editable, so maybe kartik can help.

This is my part code :

...
[
    'class'           => 'kartik\grid\EditableColumn',
    'label'           => 'Active to',
    'attribute'       => 'active_to',
    'refreshGrid'     => true,
    'value'           => function ($model) {
        return $model->active_to; // return as "Y-m-d H:i:s" format
    },
    'editableOptions' => [
        'header'       => 'Date Select',
        'placement'    => 'left',
        'inputType'    => 'widget',
        'widgetClass'  => '\kartik\daterange\DateRangePicker',
        'options'      => [
            'useWithAddon'  => false,
            'convertFormat' => true,
            'pluginOptions' => [
                'locale'           => ['format' => 'Y-m-d H:i:s'],
                'singleDatePicker' => true,
                'showDropdowns'    => true,
                'timePicker'       => true,
            ],
        ],
    ],
]
...

The problem is, everytime I try to click save button using editable, there is error output in console TypeError: data is undefined. I try to add code in editable.js#L50 :

...
        htmlEncode: function(data) {
            if(typeof data === 'undefined'){
                data = '';
            }
            var self = this;
...

and try to save again using editable in GridView, and success, no error.
@kartik-v : whether this is my mistake or script error?
Btw, thank you for the great widget!

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Up.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

up

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.