简体   繁体   English

在Javascript警报在MS CRM中不起作用后设置字段焦点

[英]Setting field focus after javascript alert not working in MS CRM

I have the following code in the OnChange() event for a field. 我在字段的OnChange()事件中具有以下代码。

alert("alert text");
crmForm.all.fieldname.SetFocus();

The page acts like the SetFocus call isn't even there. 该页面的行为就像没有SetFocus调用一样。

Anyone know why this is? 有人知道为什么吗?

EDIT: I've also tried the following to no avail. 编辑:我也尝试了以下无济于事。

crmForm.all.fieldname.Focus();
crmForm.all.fieldname.focus();
alert("alert text", function() { crmForm.all.fieldname.SetFocus()});

在DOM中,将焦点设置在元素上的函数称为focus() ,而不是SetFocus()

Turns out that retaining focus on the field from which the OnChange() method was called is broken in CRM 4 without the most recent rollup. 事实证明,在没有最新汇总的情况下,在CRM 4中破坏了对调用OnChange()方法的字段的关注。 This is a known issue with a Microsoft KB article . 这是Microsoft KB文章的一个已知问题。

To achieve the illusion of retaining focus on the field simply set the focus to a different field on the same tab first and then reassign the focus to the field from which the OnChange() event was called like so: 要实现将注意力集中在该字段上的错觉,只需先将焦点设置到同一选项卡上的另一个字段,然后将焦点重新分配给调用OnChange()事件的字段,如下所示:

alert("alert text");
crmForm.all.some_other_field_on_the_same_tab.SetFocus();
crmForm.all.fieldname.SetFocus();

Seems like the same problem exists in CRM 2011 - event when working with Xrm.Page . 使用Xrm.Page时,CRM 2011中似乎存在相同的问题-事件。
The workaround is still working: 解决方法仍然有效:

Xrm.Page.getControl("name").setFocus(true);
Xrm.Page.getControl("TheFieldYouReallyWantToFocus").setFocus(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM