Using CC::FormBuilder and a CGI::FormBuilder::Source::File .fb config file. The documentation for C::F::S::F suggest it is possible to use a reference to a sub-routine for config variables, eg:

state:
  options:  \&getstates
  sortopts: \&sortstates

but where would the getstates() & sortstates() methods go - presumably in the controller that called the formbuilder method?

But what I really want to do is the related use of a method in a validation step, and cannot get it to work from the .fb file this way:

my_field:
  validate: \&my_validation_routine

so I overloaded the field definition in the controller, like this:

$form->field(
  name => 'my_field',
  validate => my_validation_routine( $c->req->param('foo') ),
);

Firstly it seems a bit of an ugly fix, and secondly it seems counter-intuitive as the validation_routine() needs to return undef if the field validates, as returning a defined value like 1 or 'ok' or even 0 triggers the 'failed validation' flag in the $form object. Presumably this is a consequence of FormBuilder expecting a regex here?
--
Richard Jones
Leeds, UK

_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to