In-Line Validation in Visualforce Pages

In-line validation

The following Visualforce code demonstrates how to call an Apex ActionMethod after a user exits the field.  Here customer is an instance of the Account SObject which has the custom field Date_Of_Birth__c.  I want to check the age of the customer to see if he is at least 18.  This code uses the actionSupport tag to listen for the onblur event (when the user leaves the field), then calls checkDateOfBirth() method in the controller (or extension).

Visualforce InputField with ActionSupport

This Apex code from the controller inspects the date of birth field and adds an error if the date entered is not from 18 years prior to the current date.

In-line validation

Apex ActionMethod

When the user enters an age less than 18 they are shown the error message on the field widget.

Field Error

In-line error on the field

Advertisements

About mdnorton

I'm a software developer by day, martial artist by night. I dig writing code, getting some exercise, then kicking back with my home brewed beer. Nunchuck skills, yeah, I got 'em. @NortonMD
This entry was posted in Force.com, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s