php - Yii dropDownList default value -


i have code:

echo $form->dropdownlist($model,                   'defaultprinterid',                    chtml::listdata(printer::model()->findall(), 'id', 'name'),                    array('prompt' => '-- none--'));  

which gives me dropdown list this:

<select id="labeltype_defaultprinterid" name="labeltype[defaultprinterid]">     <option value="">-- none --</option> </select> 

however, when form posts, adds value table defaultprinterid 0. instead of that, how make null, since it's nullable field?

in controller, after load attributes $_post

$model->defaultprinterid = $model->defaultprinterid ? $model->defaultprinterid : null;

this changes 0 null otherwise leaves unmodified.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -