如何在 symfony 1.4 中使用 onchange 属性
我正在使用 symfony 1.4 和 propel orm。我有 3 个表,例如国家、州和县。我想使用 onchange 属性来避免过载并传递不相关的记录。如何在表单类中使用 onchange 属性。
I'am using symfony 1.4 with propel orm. I have 3 tables such as countries, states and counties. I want to use the onchange attribute to avoid overload and pass over unrelated records. How can I use onchange attribute in form classes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么在渲染字段时在表单类中而不是在视图中使用它(并与 ajax 一起使用)?假设您没有执行
echo $form
并且您正在回显每个字段(标签、错误、字段)。如果您执行echo $form
,您可能需要将其写入表单类中(我认为这属于视图中,而不是类中,但这是另一个问题)。只需在定义小部件时使用数组属性参数即可。类似于:如果您还想限制选择,则在表单类中(例如,当在国家/地区选择框中选择美国时,仅使用美国各州填充选择),将上下文作为选项发送到表单:
在你的操作中:
$this->form = newwhateverForm(array(), array('context' => $this->getContext()));
在你的表单中做一些事情就像:
这将为您提供当前提交的国家只显示该国家的州。
各县也是如此。
Why use it in the form class and not in you view (and use it with ajax) when rendering the field? That assuming you are not doing an
echo $form
and you are echoing each field (label, error, field). If you do anecho $form
, you might need to write it in the form class (imo this belongs in the view, not in the class, but that's another problem). Just use the array attributes parameter with you are defining the widget. Something like:If you want to also restrict the choices, then, in the form classes (for example to only populate a select with the US states when US has been selected in the country selectbox), send the context to the form as an option:
in your actions:
$this->form = new whateverForm(array(), array('context' => $this->getContext()));
in your form do something like:
That will get you the current submited country to display the states only for that country.
Same thing with the counties.