Re: [dfv] Enterprise implementation of dynamic error messages
Status: Inactive
Brought to you by:
markjugg
|
From: Mark S. <ma...@su...> - 2008-07-29 15:49:18
|
> I understand that dynamic error messages can be implemented by passing a > coderef to the msgs hash instead of a hashref with the standard error > messages. In fact, I've done a quick, simple implementation to get a feel > for how the functionality works. It works great for a one-off, but I'm > looking for a way to work that functionality into our enterprise (perl) web > application architecture. > > Currently, our applications provide a validator profile and the hashref of > error messages and the framework takes care of all the processing and error > formatting and display. What I'm looking for is a way to allow developers of > new applications to have their constraints generate dynamic error messages. > The most common need would be something like a max_length constraint that > should be able to indicate what the actual max_length argument passed to it > was so instead of an error like "too long" it should say "can be no more > than 15 characters". > > Does anyone have any suggestions of how to start on implementing this with > DFV? I've spent a couple of hours thinking about it and looking through the > code in DFV and DFV::Results and I the ideas I've had thus far are rather > involved and include sub-classing both of those classes and rewriting a good > bit of code. Andrew, It sounds you want error messages that are field-based, or least have the option to me of the default constraint error isn't specific enough. Here are some ideas: - I believe for each field you can see which constraint it failed. I expect in the custom 'msgs' code you can analyze this and add specific error messages then (if not in the profile). Some people do this in their templates. - You might also look at Data::Form::Elements http://search.cpan.org/~plural/Data-Form-Elements-0.61/ It provides an alternate, field-based API to DFV, allowing you to declare a custom error message for a field up front. I haven't used it myself nor heard much feedback on it, but it seems like it may be helpful to you. Mark -- . . . . . . . . . . . . . . . . . . . . . . . . . . . Mark Stosberg Principal Developer ma...@su... Summersault, LLC 765-939-9301 ext 202 database driven websites . . . . . http://www.summersault.com/ . . . . . . . . |