onFocusLost & requestFocus() combination error

I have a method which is triggered by onFocusLost event.
This method validates the field value & if the field value is not correct then
the method should give focus to the same field.

if (result) {
    plugins.dialogs.showErrorDialog('Error', message, 'OK');
    forms[formName].elements[elementName].requestFocus();	
}

The above method is working good, but it triggers 3 times. Why it is happening?

Do you have an error icon on the form?

No I don’t have any error icons.

The method is getting triggered 3 times.It should triggered when the field loses its focus,but it is also triggering on requestFocus().

Do you have an onFocusGained method on the field?

If so, then use this syntax:

if (result) {
    plugins.dialogs.showErrorDialog('Error', message, 'OK');
    forms[formName].elements[elementName].requestFocus(false);   
}

The “false” parameter says “do not execute the onFocusGained method”.

No I don’t have focus gained method.

forms[formName].elements[elementName].requestFocus(false);

Thanks, it is working as expected.

Are you sure that works?
I keep getting multiple messages.
The manual click out of the field AND the open dialog step, seem to both trigger the onFocusLost.

Here’s one workaround(that is, if your code logic allows for emptying result variable)

if (result) {
    plugins.dialogs.showErrorDialog('Error', message, 'OK');
	result = "";
    forms[formName].elements[elementName].requestFocus(false);   
}
forms[formName].elements[elementName].requestFocus(false); 

Yes , this is working in
servoy 2.2rc2
Java version 1.4.2_06-b03.

But , the following code gets triggered 3 times.

if (result) { 
    plugins.dialogs.showErrorDialog('Error', message, 'OK'); 
   result = ""; 
    forms[formName].elements[elementName].requestFocus();    
}

hmm, I tested with 2.2.rc3
Can you also do a test with this release?

What kind of variable is “result” (databaseColumn, javascriptVariable, unstoredCalc?)
Are you sure it isn’t prefilled again within your script?

I tested it with
R2 2.2rc3-build 321
Java version 1.4.2_06-b03 .
The following code is working ok.

forms[formName].elements[elementName].requestFocus(false);

The complete code is

var email = forms[formName][elementName];
var result = plugins.it2be_tools.isEmail(email);
if (result) {
    plugins.dialogs.showErrorDialog('Error', message, 'OK');
    forms[formName].elements[elementName].requestFocus(false);
}