Grid View with checkbox - form

In Yii 1 I was able to add a checkbox to the rows in CGridview and with a few other inputs, I was able to make a form that incorporated the checked rows. I have the same thing working in Yii 2, but with one major problem.

In the old application, I was able to use the filter fields to narrow down the choices before checking boxes and submitting the form. In my Yii 2 app, when I enter a value in one of the filter fields, it starts the form action which fails and I am redirected back to the grid view page without the values for $dataprovider. The old app did not treat the filter fields as part of the form, just the checkboxes.

[s]I hope this will solve the problem:

http://www.yiiframework.com/doc-2.0/yii-widgets-pjax.html#$formSelector-detail[/s]

Sorry.

Does the form share the same action url with that for the Pjax updating of the grid?

Sorry I was unable to give more detail. The real world things I’m working with are printing jobs for business cards. We print 12 to a sheet, so the jobs get put into groups. The grid view is the Job model, which is wrapped in the form that creates a new Group, group/create is the action specified.

What is confusing me is that when I use the filter fields, I see group/create in the url displayed by the browser, but what the app is attempting to render is the job/index. Since I don’t pass $dataprovider to the group/create action I get an error since job/index requires it.

To your question, the form does not share the same action, but the app seems to be doing both. What I guess is going on is that unlike Yii 1 that had a javascript when the filters were used, Yii 2 is refreshing the page. If that is the case I have no idea how to remedy the situation.

I found a solution. In my controller I was calling for the index to be rendered if the values for $_POST were not set. This worked with no filters being applied but crashed when they were. I just had to call $this->actionIndex instead of $this->render(‘index’).

Actually, the above solution did not work, but I did solve the problem.

When gii creates the index view, by default the line that says:

echo $this->render(’_search’, [‘model’ => $searchModel]);

is commented out. This view is just another form that performs the same function as the grid view filters. I reformatted the _search view form to horizontal and removed the ones in the grid view.