pungpoo / giix

Automatically exported from code.google.com/p/giix
0 stars 0 forks source link

Leave the dropDown empty if not a required field. #20

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
It is necessary to be able to leave the dropDown empty if not a required field.

Here is my suggestion for modification.

File GiixCrudCode.php
public function generateActiveField($modelClass, $column) {
        if ($column->isForeignKey) {
            $relation = $this->findRelation($modelClass, $column);
            $relatedModelClass = $relation[3];
                        $empty = $column->allowNull ? "array('empty'=>'')" : "array('empty'=>Yii:t('app', 'Select one...'))";
            return "echo \$form->dropDownList(\$model, '{$column->name}', GxHtml::listDataEx({$relatedModelClass}::model()->findAllAttributes(null, true)), {$empty})";
        }

Original issue reported on code.google.com by thiagota...@gmail.com on 2 Jun 2011 at 6:52

GoogleCodeExporter commented 8 years ago
Thanks.

Original comment by rodrigo.coelho@gmail.com on 5 Jul 2011 at 9:43

GoogleCodeExporter commented 8 years ago
I can confirm that proposed solution works. (except for the typo in 
Yii::t('app' ... missing colon). 

Original comment by luka.kle...@gmail.com on 13 Mar 2012 at 11:07