konapaz
(Konapaz)
May 28, 2014, 2:43pm
1
I created model rule for taking tabular input
array(‘table_ids’, ‘type’, ‘type’ => ‘array’, ‘allowEmpty’ => true) OR
array(‘table_ids’, ‘type’, ‘type’ => ‘array’, ‘allowEmpty’ => false)
And In view
echo $form->listBox($model, ‘table_ids’, $listdata, array(‘multiple’ => ‘true’));
Everything works ok except in the case that no item selected from the list
if allowEmpty=false no error validator occurs
both of cases (true or false) if no item checked the save fas no effect in the related items
The problem I think is that in POST submit the variable not exists so
the $model->attributes = $_POST[‘modelName’] not pass the Specific List
so the array of the model is no affected
Note: In afterFind method I fill the array table_ids from the database
How to manipulate this ?
Thanks
Konapaz
Keith
(Kburton)
May 28, 2014, 2:57pm
2
Maybe you could add something like this before that rule:
array('table_ids', 'default', 'value'=>array(), 'setOnEmpty'=>true),
konapaz
(Konapaz)
May 28, 2014, 3:06pm
3
Keith:
Maybe you could add something like this before that rule:
array('table_ids', 'default', 'value'=>array(), 'setOnEmpty'=>true),
Hi Keith thanks for the response
Validators works in setAttribute,
but afterFind I fill with data from database.
If on SetAttributes the post form contains an empty array "table_ids[]" I think everything works correctly
But in submit form the table_ids (when is empty) not exists! So validators check this attribute as exist from the database and not for the submitted form
I could check in my controller if isset($_POST[‘table_ids’]) -> $model->table_ids = array() but I want more robust way…
Any suggestion ?
Keith
(Kburton)
May 28, 2014, 3:33pm
4
Try this in combination with my first suggestion:
echo $form->listBox($model, 'table_ids', $listdata, array(
'multiple' => 'true',
'unselectValue' => '',
));
konapaz
(Konapaz)
May 29, 2014, 8:20am
6
Tips:
The first suggestion is not necessary, setAtributes will be set the attribute to empty string.
But if we want integration of our code without check empty($this->table_ids) or $this->table_ids==’’ then it is good practice to use it!