[html-formfu] mutliple selects

Carl Franks fireartist at gmail.com
Tue May 29 14:16:55 GMT 2007

On 29/05/07, Thorsten Domsch <tdomsch at gmx.de> wrote:
> Hi there,
> I've got a small Problem here. I created a custom date element,
> consisting out of three select boxes. The whole thing extends the Select
> object.
> so my yaml file looks like this:
> -type date
>  name: custom
>  start_year: 2000
>  end_year: 2005
> and produces something like this
> <select name="custom_day">1 ... 31</select>
> <select name="custom_month"> january ...december </select>
> <select name="custom_year"> ...2000-2005 ... </select>
> now i want to process the three request values... evaluate them, select
> the selected and put them together.... to custom->value
> but how (or where) the hell do i do this ?? there must be a method to
> get acces to the request vars but i can't find out which one.

Hmm, I can't think of a way to do this that isn't rather 'hackish'.

You could try making your custom element a sub-class of 'multi' - and
override the constructor to automatically add the select elements.
This way, because the selects are real fields, their values will be
processed correctly and constraints etc. will be run on each
individual element.
You can then add any needed methods such as start_year and end_year to
your custom class to do what you need.

Elements can have a process() method which is called if submitted() is
true, but before the input values are processed at all. You can access
the input there, via $self->form->query(), but it's not going to be
much use, because $form->process() will only process values for real
fields, which your multi isn't - so you'd never be able to access
'custom's value via $form->params().

This is untested, but I think if you overrode is_field() in your
block, to make it true, and overrode get_fields() to return both
itself and it's children, then the input processing would work.

I would suggest adding the following Constraint...
    type: AllOrNone
    name: custom_day
    others: [custom_month, custom_year]

This would ensure that all 3 values are set.
Then create a custom Inflator which is a sub-class of the DateTime
inflator, and uses the 3 values to set 'custom's value...
    type: +CustomDateTime
    name: custom

package CustomDateTime;
use base 'HTML::FormFu::Inflator::DateTime';
sub new {
    my $self = shift->SUPER::new( @_ );


    return $self;
sub inflator {
    my ( $self, $value ) = @_;

    my $d = $self->form->input->{custom_day};
    my $m = $self->form->input->{custom_month};
    my $y = $self->form->input->{custom_year};

    return $self->SUPER::inflator( "$d-$m-$y" );


More information about the HTML-FormFu mailing list