Symfony1 如何在symfony 1.4中使用onchange属性

Symfony1 如何在symfony 1.4中使用onchange属性,symfony1,symfony-1.4,propel,Symfony1,Symfony 1.4,Propel,我正在使用symfony 1.4和propel orm。我有3个表格,如国家、州和县。我想使用onchange属性来避免重载并传递不相关的记录。如何在表单类中使用onchange属性。渲染字段时,为什么在表单类中使用onchange属性而不是在视图中使用它(并与ajax一起使用)?假设您没有执行echo$表单,并且您正在回显每个字段(标签、错误、字段)。如果执行echo$form,可能需要在form类中编写它(在我看来,这属于视图,不属于类,但这是另一个问题)。在定义小部件时,只需使用array

我正在使用symfony 1.4和propel orm。我有3个表格,如国家、州和县。我想使用onchange属性来避免重载并传递不相关的记录。如何在表单类中使用onchange属性。

渲染字段时,为什么在表单类中使用onchange属性而不是在视图中使用它(并与ajax一起使用)?假设您没有执行
echo$表单
,并且您正在回显每个字段(标签、错误、字段)。如果执行
echo$form
,可能需要在form类中编写它(在我看来,这属于视图,不属于类,但这是另一个问题)。在定义小部件时,只需使用array attributes参数。比如:

$this->widgetSchema['state'] = new sfWidgetFormDoctrineChoice(array(blabla), array('onchange' => 'someJsFunction'));
$context = $this->getOption('context');

if (!$context instanceOf sfContext) throw new sfException('whateverForm needs the context.. bla bla');

$taintedValues = $context->getRequest($this->getName()); 
$country = $taintedValues['country'];` 
如果还希望限制选择,则在表单类中(例如,在国家/地区选择框中选择美国时,仅使用美国州填充选择),将上下文作为选项发送到表单:

在你的行动中:

$this->form=newwhateverform(array(),array('context'=>this->getContext())

在您的表格中,执行以下操作:

$this->widgetSchema['state'] = new sfWidgetFormDoctrineChoice(array(blabla), array('onchange' => 'someJsFunction'));
$context = $this->getOption('context');

if (!$context instanceOf sfContext) throw new sfException('whateverForm needs the context.. bla bla');

$taintedValues = $context->getRequest($this->getName()); 
$country = $taintedValues['country'];` 
这将使您当前提交的国家仅显示该国家的州

县也一样