0
我使用symfony 1.4和propel orm。我有3个表格,如国家,州和县。我想使用onchange属性来避免重载并传递无关的记录。我如何在表单类中使用onchange属性。如何使用symfony 1.4的onchange属性
我使用symfony 1.4和propel orm。我有3个表格,如国家,州和县。我想使用onchange属性来避免重载并传递无关的记录。我如何在表单类中使用onchange属性。如何使用symfony 1.4的onchange属性
为什么在表单类中使用它,而不是在显示字段时查看(并使用它与ajax)?假设您没有执行echo $form
,并且您正在回显每个字段(标签,错误,字段)。如果你做一个echo $form
,你可能需要写在窗体类(这是属于视图,而不是在课堂上,但这是另一个问题)。只需使用数组属性参数即可定义小部件。喜欢的东西:
$this->widgetSchema['state'] = new sfWidgetFormDoctrineChoice(array(blabla), array('onchange' => 'someJsFunction'));
如果你也想限制的选择,那么,在表单类(例如与当时美国已在全国选择框选择了美国各州只填充选择),发送上下文的形式作为一个选项:
在你的行动:
$this->form = new whateverForm(array(), array('context' => $this->getContext()));
做这样的事情:
$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'];`
这将使您获得当前submited国家显示国家只为该国家。
与县一样的东西。