function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JasonGablerJasonGabler 

Show more than one validation error message at a time?

When I force multiple validation errors on a VF page, and the error messages are set to be shown near the fields, I only get one validation error showing at a time.  This means the user would have to attempt to submit the form once per validation error... see a red error, correct it, submit, see the next one, correct it, submit, and so on.  Is there a way to get the page to light up with multiple error messages shown at the fields?

 

thanks,

 

jason

suresh.csksuresh.csk

Hi

 

Why can't you have a try with this.

 

VF:
<apex:page>
<apex:pageMessages/>  [add this to your VF page]
</apex:page>

Apex:
try {
   insert MyObject;
   } catch (Exception ex) {
     ApexPages.addMessages(ex);
    }

 

 

some resource links:

http://wiki.developerforce.com/index.php/An_Introduction_to_Exception_Handling

http://community.salesforce.com/t5/Visualforce-Development/Extra-DML-Validation-Error-Display/m-p/75448

 

 

WesNolte__cWesNolte__c

Hey

 

Doing this is tricky and makes your code messy. There is a much neater solution using jQuery, which has a number of other advantages too. Have a look here: http://th3silverlining.com/2010/03/02/visualforce-form-validation-enhanced/

 

Wes

WesNolte__cWesNolte__c

The problem arises when you have multiple exceptions that you want to catch, but a single exception handler will stop normal application exectution. It's trickier than it seems. 

JasonGablerJasonGabler

Suresh,  note that I said the messages are to show up near the fields.  You idea is the simple message at the top (or wherever you place the apex:messages tag).  Thanks anyhow.

 

jason

JasonGablerJasonGabler

Wes,

 

I have been using jquery for some things and I've used jquery validation before.  I'd love to be able to use VF's built in stuff WITH jquery... but have noticed that the error message coming back have no reconnection to the fields they are referring to?  No CCS class, nothing.  The only way I've been able to play with them with jquery is because I know that the input field and the error message are DOM siblings... sigh.

JasonGablerJasonGabler

Wes,

 

so you're saying that I'd have to catch all of the exceptions one by one in a controller to deal with them properly before validation is initiated?  Yuck.  I'm going to stick with jquery validation from now on.

 

the scary part is that if you miss something in validation, your VF application can explode...

 

jason

WesNolte__cWesNolte__c

Hi Jason

 

I'm not sure what you mean by connection, but you could certainly use CSS classes if you tinkered a bit. In the demo from that article each error sits aside it's field: http://thesilverlining-developer-edition.na7.force.com/jqueryvalidatedemo

 

Joel Dietz has also created something of an enhance VF component library that would have this built in. You can get his stuff here: http://d3developer.com/2010/06/24/jquery-enhanced-components-release/

 

Wes