drupal 选择 cck onchange 处理程序
我通过以下方式将 onchange 处理程序添加到所有 cck 字段。
function bday_form_event_node_form_alter(&$form, &$form_state) {
$form['title']['#attributes'] = array('onchange' => "titleval()");
$form['#after_build'][] = 'bday_form_event_node_form_cck_alter';
}
function bday_form_event_node_form_cck_alter($form, &$form_state) {
$form['field_date1'][0]['value']['#attributes'] = array('onchange' => "dateval()"); //Text Field
$form['field_city']['#attributes'] = array('onchange' => "cityval()"); //Select Field
}
但是 Select 的 Onchange 处理程序未添加到 dom 中。
i'm adding onchange handler to all cck fields by following manner.
function bday_form_event_node_form_alter(&$form, &$form_state) {
$form['title']['#attributes'] = array('onchange' => "titleval()");
$form['#after_build'][] = 'bday_form_event_node_form_cck_alter';
}
function bday_form_event_node_form_cck_alter($form, &$form_state) {
$form['field_date1'][0]['value']['#attributes'] = array('onchange' => "dateval()"); //Text Field
$form['field_city']['#attributes'] = array('onchange' => "cityval()"); //Select Field
}
But Onchange handler for Select is not added to the dom .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以 googletorp 所说的为基础。
这不是在 drupal 中向表单添加行为的方法。
drupal 附带了一个非常好的 JS api ,它可以帮助您做到这一点。
大致上你想要的是这样的。
Building a little on what googletorp said.
This is not the way to add behaviours to forms in drupal.
There is a very nice JS api that comes with drupal which can aid you in doing this.
Roughly what you would want is something like this.