[html-formfu] Question about DBIC-integration
Carl Franks
fireartist at gmail.com
Tue Feb 12 09:57:26 GMT 2008
On 11/02/2008, Andreas Marienborg <omega at palle.net> wrote:
> Hello :)
>
> I know got my options_from_model working nicely, just two small
> questions:
>
>
> 1: line 36 checks data_type against a regexp without checking for
> definedness/truthness, which results in alot of warnings for schema/
> sources that do this:
>
> __PACKAGE__->add_columns(qw/id title blabla/);
Ok, that should now be fixed with revision 868
> second question:
>
> I need to constraint my options in a select based on the user that is
> logged in. Is that possible, or should I start tailing trunk and try
> to cook up a patch that lets you specify a token or somesuch replaced
> by $c->user->id for instance?
I've already added support in trunk for adding a DBIC constraint based
on a value on the form stash.
So, in your element config:
---
type: Select
model_config:
DBIC:
condition_from_stash:
$column-name: $stash-key
Will essentially do:
$row->search({ column-name => $form->stash->{ $stash-key } });
So if you can get the user id onto the stash easily enough, this might
be a solution.
Otherwise, I think it would probably be best to implement this as a
custom element - a subclass of Select.
I'm not really wanting any core functionality to rely on Catalyst.
So, this would probably require abstracting the options_from_model() a
bit, to allow a hook for your subclass to add its DBIC constraint.
Feel free to create a new folder in trunk/ to experiment with this. It
would make sense to have any Catalyst-specific functionality either in
a new package HTML-FormFu-Catalyst or in the
Catalyst-Controller-HTML-FormFu dist.
...open to other suggestions though.
It's very hard to provide an automatic way to support this kind of
stuff, purely from a config file.
Either you end up with a million methods, for every option that
someone comes up with, or you end up trying to make a turing-complete
programming language in YAML :P
Carl
More information about the HTML-FormFu
mailing list