Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Validate form data, where to put it?  (Read 12019 times)
immerzeel
Courseware Beta
Jr. Member
***
Posts: 14


View Profile Email
« on: December 23, 2007, 03:51:53 »

Hi,

I am making some forms in Flash (not Flex) and of course need to validate the data entered by the user.

I already made a model.helpers.ValidateHelper class to keep the validation code centralized.

But.. my question is where do I validate. Now I do it in the Mediator of the form, sending notifications to my AlertMediator to popup with a message.

I have also seen validation methods put in the VO, which seems a very good place , but I don't know if that doesn't clashes with sending to a  AMF service.

Anyone got a good practice on this?
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #1 on: December 25, 2007, 11:17:18 »

From my experience adding methods to VO objects does not interfere with AMF calls at all. I am using Django AMF, so your mileage may vary, but it completely ignores any methods and passes only public properties of the object (I haven't tested private properties, but implicit getters and setters work).

In Flex, I validate in my MXML form component. I don't know if this is proper, but it works ;)
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
Peter
Full Member
***
Posts: 26


View Profile Email
« Reply #2 on: December 26, 2007, 03:17:55 »

I simply use a Proxy and a SimpleCommand to do validation. In short:

-register the Proxy - ValidateFormProxy - at startup (I need it all the time...)
-the viewcomponent broadcasts an onSubmit event to its Mediator (passing in the data)
-the Mediator then sends a Notification to validate a form at which point a SimpleCommand is invoked (registered as a command with the ApplicationFacade) to retrieve the ValidateFormProxy and passes in the data to be validated (via the body of the Notification)

When things don't validate - the ValidateFormProxy can send a Notification to the Mediator that needs to take action, passing errors in the body of the Notification.

When things validate - the ValidateFormProxy can send a Notification to save the form data.

The ValidateFormProxy can import an external library with utility classes to do the actual validation.
« Last Edit: December 26, 2007, 03:30:59 by Peter » Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #3 on: December 26, 2007, 07:58:06 »

Sounds like I have some refactoring to do. I like your solution Peter.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
Peter
Full Member
***
Posts: 26


View Profile Email
« Reply #4 on: December 27, 2007, 02:23:02 »

The good thing here (besides the obvious re-use) is that you can do both client side and server side validation this way. I needed the solution to add new users to the application. While I can check - for instance - an email address client side, I can't check if the provided email address is already in the database.
So, if things validate client side, the ValidateFormProxy sends a Notification that invokes a Command to retrieve a Remote Proxy that will try to save the entry. The Remote Proxy catches any server side errors (XML) and sends a Notification to a Mediator to report the errors.
Logged
Pages: [1]
Print