要在我的表单中设置 select 的默认值,我确实喜欢这样:
$def_volume = array(-1=>"Please select a volume");
$def_issue = array(-1=>"Please select issue");
$volumes = array_merge($def_volume,IssuePeer::getAllVolumesForListChoices());
$issues = array_merge($def_issue,IssuePeer::getAllIssuesForListChoices());
$this->setWidgets(array(
'keyword' => new sfWidgetFormInput(),
'volume' => new sfWidgetFormSelect(array('choices' => $volumes)),
'issue' => new sfWidgetFormSelect(array('choices' => $issues)),
));
$this->setValidators(array(
'keyword' => new sfValidatorString(array('required' => true)),
'volume' => new sfValidatorChoice(array('choices' => array_keys(IssuePeer::getAllVolumesForListChoices()))),
'issue' => new sfValidatorChoice(array('choices' => array_keys(IssuePeer::getAllIssuesForListChoices()))),
));
输出:
<select id="filterSearch_volume" name="filterSearch[volume]">
<option value="0">Please select a volume</option>
....
</select>
但是我希望有这样的输出:
<select id="filterSearch_volume" name="filterSearch[volume]">
<option value="">Please select a volume</option>
....
</select>
如果你说第一个值的值是
value="0"
,但我希望像这样返回“null”value=""
。
你尝试过吗:
$def_volume = array('' => "Please select a volume");
这似乎对我有用。
$this->widgetSchema['employee_id']->setOption('add_empty', '请选择一名员工');