On 28 January 2010 16:37, Oskari 'Okko' Ojala <okko+for...@frantic.com> wrote: > Consider this: > > - type: Checkbox > name: email_permission > constraints: > - type: Callback > message: 'You cannot turn this off when you have pending orders.' > name: orders_blocking > - type: Callback > message: 'You cannot turn this off when you have pending questions.' > name: questions_blocking > > > I'd like to reference one of multiple callbacks by name to be able to define > the error messages in YAML and to define the complicated database checks in > code. The name would be needed to match the correct Callback, like > > $form > ->get_constraint({ > name => 'orders_blocking', > type => 'Callback', > }) > ->force_errors(1); > > > but at the moment name is not allowed for Callbacks: > "cannot use name() as a setter at ..../_Field.pm" > > Is there some other method to match a correct Callback if there are many?
Constraints already have a name() method - it just returns: $constraint->field->name() You could achieve this with: package HTML::FormFu::Constraint::My::Callback; use base 'HTML::FormFu::Constraint::Callback'; __PACKAGE__->mk_item_accessors( 'my_name' ); 1; Which you'd use like: constraints: - type: 'My::Callback' message: 'You cannot turn this off when you have pending orders.' my_name: orders_blocking Carl _______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu