[英]Adding inline JavaScript to form input element in CakePHP
我正在尝试这样做:
echo $this->Form->input("filter.wijk", array(
'onChange' => 'this.form.submit()',
'type' => 'select',
'multiple' => 'checkbox',
'options' => $wijkOpties,
'label' => false)
);
但是, onChange
属性不会出现在结果HTML中。 FormHelper::input
的文档告诉我们以下内容:
* ### Options
*
* See each field type method for more information. Any options that are part of
* $attributes or $options for the different **type** methods can be included in `$options` for input().i
* Additionally, any unknown keys that are not in the list below, or part of the selected type's options
* will be treated as a regular html attribute for the generated input.
我是否以错误的方式解释了最后一句话?
您有2个选择:
1-放弃复选框,仅获得一个普通的选择列表元素/框:
echo $this->Form->input("filter.wijk", array(
'onChange' => 'this.form.submit()',
'type' => 'select',
'multiple' => true,
'options' => $wijkOpties,
'label' => false)
);
2-对有效的复选框列表进行变通(类似):
$i = 0;
foreach($wijkOpties as $value => $option){
echo $this->Form->input('filter.wijk.' . $i++, array(
'onChange' => 'this.form.submit()',
'label' => $option,
'value' => $value,
'type' => 'checkbox',
));
}
`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.