How to clear field after validation rule fails

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Sparkblender
Posts: 32
Joined: Fri Feb 01, 2013 3:31 pm
Location: USA

How to clear field after validation rule fails

Post by Sparkblender »

Hi,

I have a form where the user needs to enter detailed contact information, including his/her email address (Customer.EmailAddress) and confirm it by re-typing it into a second field (Customer.EmailAddress.Check).

I created an Update Rule for the Customer BO as follows:

Code: Select all

If Customer.EmailAddressCheck<>UNDEFINED AND Customer.EmailAddress<>Customer.EmailAddressCheck Then 
Customer.EmailAddressCheck=UNDEFINED 
REPORT ERROR 'Please re-enter your email address.  Email Address and Email Address Check must be identical.'
My intent is to clear the Customer.EmailAddressCheck field to have the user re-enter his email address in the Customer.EmailAddressCheck field.

My problem is, that the Customer.EmailAddressCheck=UNDEFINED doesn't seem to execute. The field remains with the last information the user typed in, and the contents are not being cleared. So, if the user chooses to modify the Customer.EmailAddress first, then the error message is re-issued, which is precisely what I'm trying to avoid by setting the Customer.EmailAddressCheck to UNDEFINED.

There may be other ways around solving the above use case, but my point here is: which is the mechanism by which I can clear the contents of a field, based on a certain rule being true?.

Notes:
  • I also tried assigning an empty string, but it didn't work for me either.
  • I tried selecting different combinations of the properties General>Dynamic and General>Do not run on server
Thanks.
chris29
Posts: 173
Joined: Sat Feb 06, 2010 1:45 am
Location: Australia

Re: How to clear field after validation rule fails

Post by chris29 »

try adding COMMIT TRANSACTION before Report Error

Have not tried this in Object rules only processes. The Report Error will rollback any changes prior to it being called.
Version 8.5 - Windows using MySql 8 and SQL Server - 64bit
ACDC
Posts: 1138
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: How to clear field after validation rule fails

Post by ACDC »

If Customer.EmailAddressCheck<>UNDEFINED
Try: IS DEFINED or IS UNDEFINED in your rule as opposed to <>
Then =UNDEFINED
Sparkblender
Posts: 32
Joined: Fri Feb 01, 2013 3:31 pm
Location: USA

Re: How to clear field after validation rule fails

Post by Sparkblender »

chris29 wrote:try adding COMMIT TRANSACTION before Report Error

Have not tried this in Object rules only processes. The Report Error will rollback any changes prior to it being called.
Thanks for the tip. Unfortunately it didn't work. The rule is from the Customer BO, so I'm getting the following message.
COMMIT TRANSACTION action is only allowed in processes.
I also tried DISPLAY MESSAGE, but this action also only works in processes.

Is there an action that would only display a message without rolling back the actions?

Cheers.
Sparkblender
Posts: 32
Joined: Fri Feb 01, 2013 3:31 pm
Location: USA

Re: How to clear field after validation rule fails

Post by Sparkblender »

ACDC wrote:
If Customer.EmailAddressCheck<>UNDEFINED
Try: IS DEFINED or IS UNDEFINED in your rule as opposed to <>
Then =UNDEFINED
I changed the condition to IS DEFINED as you suggested. This seems to be more proper, thanks. Nevertheless, it does yield the same results. In fact, the mismatch between Customer.EmailAddress and Customer.EmailAddressCheck was already being detected. The problem seems to be during the action, i.e. the assignment Customer.EmailAddressCheck=UNDEFINED is not being reflected in the form.
ACDC
Posts: 1138
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: How to clear field after validation rule fails

Post by ACDC »

Customer.EmailAddressCheck=UNDEFINED
remove this from the rule and just Report Error if they not equal -

BTW, if you use rule in dynamic recalc on forms, you may get the right behaviour

Also , reset form if the form is not too large , otherwise existing take on will be lost.....
IF NEW and WAS CHANGED may also be needed for future editing
Sparkblender
Posts: 32
Joined: Fri Feb 01, 2013 3:31 pm
Location: USA

Re: How to clear field after validation rule fails

Post by Sparkblender »

ACDC wrote:
Customer.EmailAddressCheck=UNDEFINED
remove this from the rule and just Report Error if they not equal -
If we remove this action, how are we going to accomplish the goal of resetting the field?
ACDC wrote:BTW, if you use rule in dynamic recalc on forms, you may get the right behaviour
Yes, I tried this already:
Sparkblender wrote:I tried selecting different combinations of the properties General>Dynamic and General>Do not run on server
In fact, without this setting, the conditions don't get triggered.
ACDC wrote:Also , reset form if the form is not too large , otherwise existing take on will be lost.....
IF NEW and WAS CHANGED may also be needed for future editing
Not sure I understand what you are suggesting.
It would be annoying to the end user, having to re-type all the information. Unless there is no other way, I'd rather NOT reset the whole form.


Thanks!
ACDC
Posts: 1138
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: How to clear field after validation rule fails

Post by ACDC »

sorry, just shooting from the hip - not at my dev machine.

I did work on something like this a while back. I'll dig it up and get back to you
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: How to clear field after validation rule fails

Post by Rennur »

Add a checkbox (Y/N attribute): IsEmailCheckFailed

Rule 1 - IsEmailCheckFailed flag:

Code: Select all

If Customer.EmailAddress IS DEFINED AND Customer.EmailAddressCheck IS DEFINED AND  Customer.EmailAddress<>Customer.EmailAddressCheck AND NOT(Customer.IsEmailCheckFailed WAS CHANGED TO 'Yes') Then 
Customer.IsEmailCheckFailed='Yes' 
Customer.EmailAddressCheck=UNDEFINED 
 


Tick 'Dyanmically re-calculate values' (in the Advanced tab)

Rule 2 - Validation Error Message:

Code: Select all

If Customer.EmailAddress IS DEFINED AND Customer.EmailAddressCheck IS DEFINED AND  Customer.IsEmailCheckCorrect WAS CHANGED TO 'Yes' Then 
REPORT ERROR 'Please re-enter your email address.  Email Address and Email Address Check must be identical.'


Tick 'Dyanmically re-calculate values' (in the Advanced tab)

Rule 3 - Reset IsEmailCheckFailed to 'No':

Code: Select all

If Customer.EmailAddress IS DEFINED AND Customer.Customer.EmailAddressCheck IS UNDEFINED AND Customer.IsEmailCheckFailed WAS CHANGED TO 'Yes' Then 
Customer.IsEmailCheckFailed='No'  
Tick 'Dyanmically re-calculate values' (in the Advanced tab)

You might have to play around with the above rules a bit.
Sparkblender
Posts: 32
Joined: Fri Feb 01, 2013 3:31 pm
Location: USA

Re: How to clear field after validation rule fails

Post by Sparkblender »

Rennur wrote:Add a checkbox (Y/N attribute): IsEmailCheckFailed ...
Thanks for the tip Rennur. I actually started exploring down that road as well.

After some more testing, I've been able to narrow down on the actual issue.

I found that by just using the following rule I'm able to clear the field content:

Code: Select all

If Customer.EmailAddress IS DEFINED AND Customer.EmailAddressCheck IS DEFINED AND Customer.EmailAddress<>Customer.EmailAddressCheck Then 
Customer.EmailAddressCheckFailed='Yes' 
Customer.EmailAddressCheck=UNDEFINED 
This will actually clear the Customer.EmailAddressCheck field, but only as long as I remove the REPORT ERROR action. The REPORT ERROR action does seem to roll back previous changes as expected, and as noted previously by chris29:
chris29 wrote:The Report Error will rollback any changes prior to it being called.
This explains why the field was not being reset.

So, the next challenge is: how do I display a pop-up message without rolling back the changes?

I tried the following so far:

1. Use DISPLAY MESSAGE instead of REPORT ERROR in Customer BO rule.
Using the following rule in the Customer BO will yield an "Internal Error" (see https://www.screencast.com/t/LoXtrFJ3W. Does anyone know what this message means?

Code: Select all

If Customer.EmailAddress IS DEFINED AND Customer.EmailAddressCheck IS DEFINED AND Customer.EmailAddress<>Customer.EmailAddressCheck Then 
Customer.EmailAddressCheckFailed='Yes' 
Customer.EmailAddressCheck=UNDEFINED 
DISPLAY MESSAGE ASYNCH ClOSABLE TOP_LEFT 'Email Addresses must be identical' 
I thought that this message may be due to a warning that appeared (see https://www.screencast.com/t/0oAU1DiWQwfo), stating that the DISPLAY MESSAGE should be used in processes and not BO rules; so I tried the following.

2. Use DISPLAY MESSAGE in process called by Customer BO rule.
This is the Customer BO rule calling the Customer_EmailAddressCheck process:

Code: Select all

If Customer.EmailAddress IS DEFINED AND Customer.EmailAddressCheck IS DEFINED AND Customer.EmailAddress<>Customer.EmailAddressCheck Then 
Customer_EmailAddressCheck 
This is the Customer_EmailAddressCheck process being called:

Code: Select all

If Customer.EmailAddress IS DEFINED AND Customer.EmailAddressCheck IS DEFINED AND Customer.EmailAddress<>Customer.EmailAddressCheck Then 
Customer.EmailAddressCheck=UNDEFINED 
DISPLAY MESSAGE ASYNCH ClOSABLE TOP_LEFT 'Email Addresses must be identical' 
This time, I don't get the warning message after saving the process, but I do get the same "Internal Error" as before (see https://www.screencast.com/t/LoXtrFJ3W.

After running out of options I ask:

  • * How do I display a pop-up message without rolling back the changes in a form?
    * Why am I getting the "Internal Error" message described above?
Thanks for your contributions.
ACDC
Posts: 1138
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: How to clear field after validation rule fails

Post by ACDC »

If you look at the way AIM handles a password attribute, the confirmation is done via a pop-up form when the form is saved. There is obviously a reason for this, otherwise, it would be done similar to the way you are attempting.

Maybe you should try using a similar concept of using a pop up just for the email confirmation form or alternatively do it with a script on the Advanced button (Maybe someone in the forum could assist with a script)

There is an option on the text attribute to prompt for confirmation but only if it is a password field which is displayed encrypted, so that would not help. It would be nice if this option did not require it to be a password attribute and just offered a confirmation prompt.

My way of dealing with this in the past was to prompt for the email address right up-front before the rest of the data is taken on, handle confirmation and form refresh before proceeding with the rest of the take on.... (its a workaround to the way its normally done but achieves the same result )

In fact, maybe it's not a workaround, just thinking, a lot of sites handle the email validation upfront when registering
Sparkblender
Posts: 32
Joined: Fri Feb 01, 2013 3:31 pm
Location: USA

Re: How to clear field after validation rule fails

Post by Sparkblender »

ACDC wrote: My way of dealing with this in the past was to prompt for the email address right up-front before the rest of the data is taken on, handle confirmation and form refresh before proceeding with the rest of the take on.... (its a workaround to the way its normally done but achieves the same result )

In fact, maybe it's not a workaround, just thinking, a lot of sites handle the email validation upfront when registering
Sounds like this is the way to go.

Still, I'm having trouble understanding why it's not possible to issue a message/popup using the DISPLAY MESSAGE function, and why we are getting the "Internal Error" message as we try to do so.

I'm thinking there will be other use cases where issuing a message in dependence of field validation is required, especially when designing more complex forms.

Maybe a question for technical support? Maybe a new feature to add?

Thanks!
aware_support
Posts: 7523
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: How to clear field after validation rule fails

Post by aware_support »

The easiest solution is to write a Javascript plugin that would perform the checking and reset the field. With this approach there is no need to get the rules involved or add other attributes. The script roughly is this (we haven't tested it - if you want us to test it you need to pay for support).

Render script of the form.

// save original function definition
var oldSave = parser.validateAndSaveForm;

// redefine it
parser.validateAndSaveForm = function (saveOper, closeOper) {
var emailF = this.getField ("EmailAddress");
var emailF2 = this.getField ("EmailAddressCheck");
if (emailF.getValue () != emailF2.getValue ())
{
// reset the fields
emailF.setValue ("");
emailF2.setValue ("");

// error message
alert ("Not equal");
return;
}

// call the original implementation
oldSave.call (this, saveOper, closeOper);
};
Aware IM Support Team
Sparkblender
Posts: 32
Joined: Fri Feb 01, 2013 3:31 pm
Location: USA

Re: How to clear field after validation rule fails

Post by Sparkblender »

Great support, thank you!

Cheers.
Post Reply