Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

How do I reset a mandatory field after it has been filled in?

Avatar

Level 2

I've set the required fields on a form to have a highlighted background colour on validation when they haven't been filled in. The problem is, when a user does fill in the field, the highlighting remains and is visible to the recipient when the form is emailed. How can I get the highlighting to dynamically turn off when the field has data?

Thanks!

5 Replies

Avatar

Level 2

Major modification to the question. The above behaviour was happening on several forms I created, but I just ran across a form that is exhibiting the proper behaviour. I just need to figure out the difference between them. If anyone has any insights in the meantime, I'd be happy to hear them.

Avatar

Level 10

If the user enters a value in the filed, then you need to set the background color back to white in the exit event of the field.

if(Field.rawValue != null && Field.rawValue != "")

     Field.border.fill.color.value = "255,255,255";

Thanks

Srini

Avatar

Level 2

Thanks Srini, but this should be happening automatically or it's way too much to have to coordinate for every field on every form. That was the gist of my second post - the other form I opened does this automatically. And when I create a new form from scratch, it also works fine automatically. So my work-around for now is to recreate all the forms that have problems. A pain, but faster in the long run than trying to get to the bottom of the issue.

It seems to me that there's some flakiness in Designer - at some point after changing various settings in the UI and Form Properties, the ColorFieldsValidation XML gets messed up and this weird behaviour starts happening. For example, in the forms that don't work, the background colour takes over the whole field, including the borders, whereas in the forms that work, the border remains intact. I certainly haven't done anything to affect this other than change the global validation properties through the standard UI.

Steve

Avatar

Level 4

Interesting, when using the required fields function even in a blank form, the fields still have red borders even after the user enters something.  Only the following script works:

if (this.rawValue != null) {

this.mandatory = "disabled";

}

else {this.mandatory = "error";

}

This has to be placed on all fields though, or you could make a Script Object function and call it from every field.  I know in earlier versions you could "propagate" exit events to cover all fields, but I only know how to do this on every field. 

Anyways, I decided to not use the built-in required field function but to instead create a For Loop that checks for null fields upon validation. 

Avatar

Level 2

I have the advantage of creating these forms for an Intranet site where I can dictate a target version of 9.1 or higher in Form Properties > Defaults. When you specify 9.1, you get the option to use global settings for Show Dialog Message, Color Failed Fields, Color Mandatory Fields, and Set Focus. Certain combinations of these do in fact remove the border and background fill when required fields have been filled in. (Although even selecting "Don't show any message boxes at all" still results in that annoying "Submit cancelled" message box.)

This works well for me...when it works. But as in my original post, the settings can get twisted resulting in non-standard behaviour that's beyond my abilities to chase down.