In one of my views i have a GridView which displays some textfields and checkboxes.
The problem is that when i select a checkbox,enter some datas in the textfields and submit the page, the checkbox is not checked anymore, but the text that i entered in the text fields are displayed. There’s is a way in the CgridView to keep the state of the checkbox after
reloading the page (displaying error message before saving data to database), as is the case for the textfield ?
As I understand, you use form and GridView to select some items from it to be submited too. May be the better way is to use a simple list of checkboxes?
Using the list of checkboxes you can pass to CHtml::checkBoxList array of values which should be checked. And this array you can get in controller after submitting the form and than pass it to view.
Simple example
[b]
in view file:[/b]
echo CHtml::beginForm();
echo CHtml::checkBoxList('userId', $userId, CHtml::listData(User::model()->findAll(), 'id', 'login'));
... other form fields ...
echo Chtml::submitButton('Post');
echo CHtml::endForm();