kartik-v / yii2-editable

An enhanced editable widget for Yii 2.0 that allows easy editing of displayed data with html inputs, widgets and more.
http://demos.krajee.com/editable
Other
112 stars 55 forks source link

Editable doesn't set display value to false if type is INPUT_CHECKBOX #92

Open nagyt234 opened 9 years ago

nagyt234 commented 9 years ago

I'm using the following column in GridView::widget:

<?= GridView::widget([
  ...
  'columns' => [
    ...
   [
      'class' => 'kartik\grid\EditableColumn',
      'attribute' => 'is_calculated',
      'editableOptions' => [
        'inputType' => \kartik\editable\Editable::INPUT_CHECKBOX,
        'displayValueConfig' => [0 => Yii::t('yii','No'), 1 => Yii::t('yii','Yes')],
      ]
    ]

It works perfectly, however if in the edit form the checkbox status is changed from checked to unchecked, the controller is called, the value of is_calculated in the database is set to false (0), the JSON call returns HTML OK, but the value in the grid is not updated.

If the checkbox status is changed from unchecked to checked, it works perfectly.

kartik-v commented 8 years ago

You need to parse the POST and model values correctly and convert any boolean or string to int.

raimon-segura commented 6 months ago

Hi @kartik-v !,

Its not really solved when the checkbox is unchecked, if you don't return the modified valuem then the label is not updated because in the source code is wrong => $input.val() this not return if its checked or not, it should be done using $input.prop('checked')

There are 6 $input.val() in the source code: https://github.com/kartik-v/yii2-editable/blob/master/src/assets/js/editable.js#L201 https://github.com/kartik-v/yii2-editable/blob/master/src/assets/js/editable.js#L223 ...

As a temporary workarorund i'm doing function editableSuccess(event, val, form, data){ // display label from checkbox if($(event.currentTarget).closest('.kv-editable').find('.tb-checkbox-editable').length==1){ var isChecked = $(event.currentTarget).closest('.kv-editable').find('.tb-checkbox-editable input[type="checkbox"]').prop('checked') var value = isChecked ? 1 : 0; var displayValue = $(event.currentTarget).closest('.kv-editable').find('.tb-checkbox-editable input[type="checkbox"]').attr('data-translate-' + value) setTimeout( function(){ $(event.currentTarget).closest('.kv-editable').find('.kv-editable-value').html(displayValue) }, 100) } }

By the way, I've added a css class as well in the configuration: ... 'inlineSettings' => [ 'options' => [ 'class' => 'card panel panel-default ' . $tbCssClass, ], ....

Thanks!

kartik-v commented 6 months ago

Thanks for the update. Could you submit a PR for this?