I have a method that fires off based on the field onFocusLost.
Here is the method:
if(potential_revenue.search(/[^0-9]/g) == 0)
{
plugins.dialogs.showErrorDialog( 'Not-a-Number', "The potential revenue field has non-numerical characters in it.\nPlease use only numbers in this field.", 'OK');
elements.potential_revenue_field.requestFocus();
}
The problem I am having is that it throws me into a big loop. I want it to bring up the field so that the user can correct their mistakes, but I am stuck in a loop. What am I missing or what additional code do I need to add?
If I trigger the method on onDataChange instead, the focus comes up on the field and then quickly goes away. Also, not the desired effect.
I was looking through the Forum for OnFocusLost posts because I’ve been having some issues when I came across your post and noticed a couple of things. On your regex I think there are a couple of issues with the search function. I believe what is returned from that function is either the location of the found matching expression or -1 if nothing is found. So in your example I think you should change the equality check to either ‘> -1’ or ‘>= 0’. ‘search’ just looks for anything that matches and 0 (zero) in this case means it found a match at the first character. Because it just looks for the first match, the ‘g’ (global) qualifier has no meaning with search and can be left out.
As a sidepoint, these types of things are often fun to have as global methods which can then be tied to any number field on any form. Taking your example you could do something like this if you wanted to:
var elemName = application.getMethodTriggerElementName();
var formName = application.getMethodTriggerFormName();
var colName = forms[formName].elements[elemName].getDataProviderID();
if(forms[formName][colName].search(/[^\d]/) > -1)
{
plugins.dialogs.showErrorDialog( 'Not-a-Number', "The " + elemName + " field has non-numerical characters in it.\nPlease use only numbers in this field.", 'OK');
forms[formName].elements[colName].requestFocus();
return false;
}
You don’t have to get the data provider ID if you use the same element name as the data provider name in your database but this allows you to name your elements in a way that is more understandable for your users.