[Html-widget] latest formfu developments

Carl Franks fireartist at gmail.com
Fri Feb 23 16:05:02 GMT 2007


The past week has seen a few formfu developments...

I18N support has been added, with all error messages being moved out
to the FormFu/I18N/en.pm package.
You can also alternatively provide your own i18n object or package, to
allow the messages to come from your main application's localized
message files.
The formfu catalyst controller now allows provides for integration
with the Catalyst::Plugin::I18N or a compatible module.

Sitting alongside filters and constraints, there are now 2 new
namespaces: Deflator and Inflator.
These are similar in idea to DBIx::Class's InflateColumn.
If, for example, you feed $field->default() with a DateTime object,
and you want to ensure the field value is displayed in a certain
format, you could do:
    $field->deflator( 'Strftime' )->strftime( '%d/%m/%Y' );

Likewise, you can ensure the value from $result->params->{date} is a
DateTime object with the following:
    $field->inflator( 'DateTime' )->parser( strptime => '%d/%m/%Y' );
(passing parser() any value that DateTime::Format::Builder::parser() accepts)

These 2 features allow for seamless integration with DBIx::Class, all
from the form config/setup, without any extra code.
The Strftime deflator was developed specially for the
Dojo::DropdownDatePicker element - you would of course need a smarter
solution for parsing dates that a human will have typed.

The css has also been updated to improve the rendering of error messages.
Also containers now automatically get the class name 'label' added if
the field has a label defined. This allows the example css to do away
with the 'nolabel' class name hack.
The css editor/preview application has also been updated with these changes:
http://www.fireartist.com/html-formfu-cssapp/

Form fields now have a default() method.
For most fields, this is just an alias to value() - except for
Checkbox and Radio fields, where you would normally set its value, but
may or may not set a default value.
This means we no longer have to manually set the 'checked' attribute
in our code, instead just setting default().
The DBIx::Class::FormFu entension has also been updated - the
fill_formfu_values() method now expects a $form object, not a $result
- this is changed back to how DBIx::Class::HTMLWidget does it, as it
makes more sense conceptually, and (because it's setting
$field->default internally) it now works properly if the result is
being re-displayed after errors.

The internals of constraints and filters has been completely reworked.
Now, if you list multiple names - like so:
    $form->constraint( Required => 'foo', 'bar' );
it creates a new constraint for each of the named fields.
This means fields which abused(?) this mechanism, such as
    $form->constraint( DependOn => 'foo', 'bar' );
now work differently:
    $form->constraint( DependOn => 'foo' )->others( 'bar' );

Take note though, that if you list multiple names - because it returns
multiple constraints, chained methods no longer work.
Because I'm now tending to define all forms in config files, this
isn't an issue.
You could work around the issue with an idiom such as:
    map { $_->callback( \&my_sub ) }
        $form->constraints( Callback => 'foo', 'bar' );

The constrain_fields() method has been removed, because now if you add
a constraint or filter without listing any names, it immediately
creates that constraint/filter for every field already on the form.

I've also copied over lots more of the constraints from the
HTML::Widget package, and added support for 'Not_' constraint names.

I hope this has been helpful.
Cheers,
Carl



More information about the Html-widget mailing list