Strange behaviour in onFocusGained

I’ve added the following method to onFocusGained for the field “name”. The purpose is to give the end user an advisory if there is already content in the field. Instead it goes into a perpetual loop, endlessly repeating the message.

if (name)
{
	var msg = 'Before performing radical editing on this field, please review how this field is currently being used in Company.'
	plugins.dialogs.showWarningDialog('Warning', msg);
}

What am I not understanding?

Version R2 2.1.1-build 313
Java version 1.4.2_05-b04 (Windows XP)

Give the field a property name: name

Try this:

if (name) 
{ 
   var msg = 'Before performing radical editing on this field, please review how this field is currently being used in Company.' 
   plugins.dialogs.showWarningDialog('Warning', msg); 
	elements.name.requestFocus(false)
}

At first I thought your line of code would take the cursor out of the field and prevent editing. Surprise, it doesn’t. The cursor remains in place! And the loop ends. Thanks Harjo.

I’m puzzled why such a simple function should go into an infinite loop in the first place.

That is because, you show a popup (the cursor is out the field) than if you close the popup, the cursor is put back in the field, and is firing at the same time the onFocus method again

now with the extra code, de element is requested focus, without firing the onFocus method (that’s the false option)

If you make the false, true again, you’ll end up in a loop again.