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

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

Open
nagyt234 opened this issue Sep 17, 2015 · 3 comments
Open

Comments

@nagyt234
Copy link

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
Copy link
Owner

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

@raimon-segura
Copy link

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 kartik-v reopened this Feb 27, 2024
@kartik-v
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants