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

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

问题描述

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

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中禁用焦点? p>

Is there a way to disable focus in Primefaces?

推荐答案

您可以更改默认行为;

You can change the default behavior;

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.

我建议创建一个js文件,如primefaces-overrides.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.

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

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