简体   繁体   中英

Setting field focus after javascript alert not working in MS CRM

I have the following code in the OnChange() event for a field.

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

The page acts like the SetFocus call isn't even there.

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. This is a known issue with a Microsoft KB article .

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:

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 .
The workaround is still working:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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