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

GridView filter for boolean columns or numeric columns with value=0 broke after update to 2.0.46 #19508

Closed
alnidok opened this issue Aug 20, 2022 · 2 comments
Milestone

Comments

@alnidok
Copy link
Contributor

alnidok commented Aug 20, 2022

\yii\grid\GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        'id',
        'approved:boolean',
    ],
])

GridView with boolean column and filter row. Filter dropdown for column "approved" has 3 options:
empty (prompt), Yes(=1), No(=0)
5ff17638f7

I expect to see empty value (prompt) after select empty option and applying filter. And it works correct on v2.0.45.
But it works incorrect on v2.0.46 - render selected option with value=0 after filter applying.
0067a79267

What steps will reproduce the problem?

Select empty option in filter.

What is the expected result?

<select class="form-control" name="approved">
    <option value=""></option>
    <option value="1">Да</option>
    <option value="0">Нет</option>
</select>

What do you get instead?

<select class="form-control" name="approved">
    <option value=""></option>
    <option value="1">Yes</option>
    <option value="0" selected="">No</option>
</select>

Additional info

Q A
Yii version 2.0.46
PHP version 7.3.29
Operating system Debian (yiisoftware/yii2-php:7.3-apache)
@BrianVB
Copy link

BrianVB commented Aug 22, 2022

This is the related issue with the commit that did it I believe: #19324

This has affected many of my GridViews and there are probably many effects cascading from it. Any view that I leave a boolean filter unselected automatically changes to a false value and ruins subsequent uses of the grid.

@dmitry-kulikov
Copy link
Contributor

It affects more than GridView. Actually it affects any dropDownList, listBox and may be widgets based on them if options are unlucky and contain item with 0 key. Consider the following code:

echo Html::dropDownList(
    'test_dropdown',
    '',
    ['1' => 'Yes', '0' => 'No'],
    ['prompt' => 'Select']
);
echo '<br/><br/>';

echo Html::listBox(
    'test_list_box',
    '',
    ['1' => 'Yes', '0' => 'No'],
    ['prompt' => 'Select']
);
echo '<br/><br/>';

echo \kartik\select2\Select2::widget(
    [
        'name' => 'test_select2',
        'value' => '',
        'data' => ['1' => 'Yes', '0' => 'No'],
        'options' => ['prompt' => 'Select'],
    ]
);

Prior to 2.0.46:
old
Since 2.0.46:
new

It seems to be we have to add "strict" everywhere to have adequate UI:

echo Html::dropDownList(
    'test_dropdown',
    '',
    ['1' => 'Yes', '0' => 'No'],
    ['prompt' => 'Select', 'strict' => true]
);
echo '<br/><br/>';

echo Html::listBox(
    'test_list_box',
    '',
    ['1' => 'Yes', '0' => 'No'],
    ['prompt' => 'Select', 'strict' => true]
);
echo '<br/><br/>';

echo \kartik\select2\Select2::widget(
    [
        'name' => 'test_select2',
        'value' => '',
        'data' => ['1' => 'Yes', '0' => 'No'],
        'options' => ['prompt' => 'Select', 'strict' => true],
    ]
);

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

4 participants