如何禁用 Primefaces 对话框中第一个输入的焦点? [英] How to disable focus for the first input in a Primefaces Dialog?

查看:19
本文介绍了如何禁用 Primefaces 对话框中第一个输入的焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有一个对话框,其中包含一个输入字段 (Date, Calendar) .问题是打开对话框后日历直接打开,因为焦点设置在第一个输入上.

I have a Dialog in my Page, which contains a input field (Date, Calendar) . The problem is that the calendar opens directly after opening the dialog, because the focus is set on the first input.

有没有办法在 Primefaces 中禁用焦点?

Is there a way to disable focus in Primefaces?

推荐答案

您可以更改默认行为;

http://forum.primefaces.org/viewtopic.php?f=3&t=29050

您始终可以覆盖小部件的默认行为,例如防止日历聚焦于对话框打开;

You can always override default behaviors of widgets, for example to prevent calendar focus on dialog opening;

PrimeFaces.widget.Dialog.prototype.applyFocus = function() {
  var firstInput = this.jq.find(':not(:submit):not(:button):input:visible:enabled:first');
  if(!firstInput.hasClass('hasDatepicker')) {
      firstInput.focus();
  }
}

原代码为;

PrimeFaces.widget.Dialog.prototype.applyFocus = function() {
  this.jq.find(':not(:submit):not(:button):input:visible:enabled:first').focus();
}

如果您将覆盖放在 PrimeFaces 资源之后,那么您的 applyFocus 实现将被选择并使用.

If you put your override after PrimeFaces resources then your applyFocus implementation will be picked up and used instead.

我建议创建一个像 primefaces-overrides.js 这样的 js 文件并把这样的东西放在里面,虽然有一个缺点,因为你是针对低级 apis 编码的,你需要注意迁移过程中的回归,尽管我们的目标是保持尽可能向后兼容.

I'd suggest creating a js file like primefaces-overrides.js and put things like this inside, one disadvantage though since you are coding against low level apis, you need to watch out for regressions during migrations although we aim to keep backward compatibility as much as we can.

这篇关于如何禁用 Primefaces 对话框中第一个输入的焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆