开发者

Symfony forms: display a checkbox (with initial state of unchecked)

I am using开发者_Go百科 Symfony 1.3.x for a project.

In the configure() method of one of my forms, I have the following code:

'terms' => new sfWidgetFormInputCheckbox(array('value_attribute_value'=>'terms', 'default' => false )),

The idea is to present the user with a checkbox (default unchecked), which the user will have to check before the form validates.

The problem is that when I display the form, the checkbox is ALWAYS already checked (i.e. selected) - which defeats the purpose of enforcing user confirmation with a checkbox.

Does anyone know how to resolve this?


Default form values in Symfony essentially have an undocumented hierarchy. It is (higher numbers have higher precedence):

  1. The default value of the widget.
  2. If the form is for a new record, the value of the record.
  3. The form level default for the widget (yes, widgets and forms can keep track of SEPARATE defaults).
  4. If the form is for an existing record, the value of the record.

My guess is one of 2, 3, or 4 is superseding your widget-level default. Note that 3. supersedes 4. when set default is called after sfFormDoctrine calls updateDefaultsFromObject.


$this->setDefault("is_tested", false);  // unchecked checkbox


some more examples

$this->widgetSchema['listing_status'] = new sfWidgetFormInputCheckbox(array(),array('value'=>1));
$this->setDefault('listing_status',1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜