[html-formfu] Validating unique names

Carl Franks fireartist at gmail.com
Thu Jun 5 13:35:55 BST 2008


2008/5/14 Ton Voon <ton.voon at altinity.com>:
>
> On 14 May 2008, at 17:45, Ton Voon wrote:
>
>> $field->validator('Object')->object( $object );
>
> I've just thought this is too limiting, because this means there's only one
> method (validate_value) per object class.
>
> So instead, I propose this syntax:
>
> $field->validator( $object )->method( "check_unique_column" )
>
> Where FormFu will create a new HTML::FormFu::Validator::Object instance and
> then call $object->validate_unique_column( $form, $new_value ) at the point
> of validation.
>
> I think this makes sense because if validators are 'intended for
> higher-level validation, such as business-logic and database constraints
> such as "is this username unique?"' (quoted from pod), then the core
> validation logic should reside at the object model. But we'd be helping out
> with some basic methods that can be incorporated into
> DBIx::Class::HTML::FormFu.

I'm not keen on this approach, because it's already possible to write
your own validators that inherit from HTML::FormFu::Validator
Doing this gives you much more flexibility, as you can decide whether
you want to override validate_value(), validate_values() or process(),
depending on how much you want to change the default behaviour.

You can also have these extensions in your application or workplace's
own namespace, such as MyApp::FormFu::DBICUnique, just make sure you
prefix the name with a "+" in the config, and it'll work.
   constraint:
     - type: '+MyApp::FormFu::DBICUnique'

I think the correct approach to the "unique" constraint, would be
something like the HTML::FormFu::Constraint::DBIC::Unique that Jonas
wrote last year.
It was posted to the html-widget mailing list, and is available in this archive:
http://grokbase.com/topic/2007/04/26/html-widget-html-formfu-constraint-dbic-unique/P_YY1Z7pdHmnoycy8mhVvbmFTrs

(Whether it's in the Constraint or Validator namespace, I don't really mind).

Carl



More information about the HTML-FormFu mailing list