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

Multiple-value filter inputs (eg. Select2) throw Array to string conversion error after filtering #1079

Open
12 of 17 tasks
BelegUS opened this issue Oct 3, 2023 · 0 comments
Open
12 of 17 tasks

Comments

@BelegUS
Copy link

BelegUS commented Oct 3, 2023

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-grid.
  • This is not an usage question. I confirm having gone through and read the documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

  1. Create some GridView with ActiveDataProvider that has a column with active filter
  2. Set that column to use Select2 filter with some data and multiple input allowed:
'filterType' => GridView::FILTER_SELECT2,
'filterWidgetOptions' => [
   'options' => [
      'multiple' => true,
   ]
],
  1. Try filtering with that filter.

Expected behavior and actual behavior

When I follow those steps, I see Array to string conversion error from yiisoft/yii2/helpers/BaseHtml.php at line 569 is thrown.

I was expecting the filter to be rendered properly with values I selected

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 3.6.1
  • yii2-grid version: 3.5.3

Isolating the problem

  • This bug happens on the demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-grid without other plugins.

Workaround

  • Setting 'filter' => '' (empty string) for that data column makes the filter work fine

Reason for the bug and possible solution

kartik\grid\DataColumn in renderFilterCellContent() method starts by calling parent implementation (so Yii2 native DataColumn::renderFilterCellContent()). All parent implementation does is creating basic dropdown/text input filter, which obviously cannot take array data Select2 uses. As parent implementation starts by checking if filter is a string and returns it instead in such scenario - so that kartik implementation can do its own "magic" - it skips the faulty (and unnecessary) native filter creation.

Possibly parent call can be omitted when filterType is specified or 'filter' => '' could be set by default when filterType is specified? Setting it manually for each column (filter) feels hacky.

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

1 participant