dimanche 1 novembre 2009

A simple workaround to the SetFocus non sticking issue (Crm 4.0)

The Sdk is pretty clear: the SetFocus function "Sets the focus, changes tabs, and scrolls the window as necessary to show the specified field."


At our customer, what this does is: when the form opens, the focus is changed only for like one milisecond or so and then switches back to default focus, first tab, first field I think. This bug is supposed to be fixed since Update Rollup 1 for Crm 4.0. There is a specific hotfix included in that rollup. And for the record, there was the exact same bug in Crm 3.0, here is the kb. Problem, the issue still happens at the customer, so I have to fix it.

Not so easy to solve at first sight. But after some good thinking, here's the solution I came up with :

var oField = crmForm.all.crm_myfield;
oField.onblur = function() {
  oField.onblur = null;

Word of explanation: the onblur event is triggered when an element loses the focus.
So, crmForm loads, I call SetFocus, the field receives the focus and after one milisec loses it. So the bug has been executed. Then, onblur is called, and the field gets the focus again. To allow the user to click on other field, remove the onblur event. This is a quite simple and effective workaround.

Untested on Crm 3.0, but probably works.

That's it!

Aucun commentaire:

Enregistrer un commentaire