[jifty-devel] Two questions about Actions
Jesse Vincent
jesse at bestpractical.com
Mon Dec 11 10:24:49 EST 2006
On Mon, Dec 11, 2006 at 04:15:33PM +0100, Agostini yves wrote:
> Le lundi 11 décembre 2006 à 09:41 -0500, Edward Funnekotter a écrit :
> > Hi,
> >
> > I haven't found any documentation to answer these yet (forgive me if I
> > missed them):
> >
> > 1. Is it possible to populate an Action's selection field at runtime?
> > What I am trying to do is have a selection box in a form that has a
> > subset of a list of items that is dependent on the user. I tried the
> > following:
> >
> > param group_name =>
> > label is 'Group Name',
> > type is 'select',
> > valid_values are sub { get_groups(); };
> >
> > But it seems that giving a code ref to the valid values is not
> > acceptable.
>
> I don't think it's possible in action
> I make this yesterday by making my own html form
What we've done in the past is to do this in the arguments sub. (Which,
yes, is deprecated, but I haven't yet spent enough time with the param
syntax to know the answer with it off the top of my head)
sub arguments {
my $self = shift;
return $self->{__cached_arguments} if (exists $self->{__cached_arguments});
my $args = $self->__get_cache->{$self->__cache_key($self->record)} ||=
$self->SUPER::arguments();
if (my $owner_id = $record->owner->id) {
$args->{'owner_id'}{'default_value'} = $record->owner->email;
if ( $owner_id == BTDT::CurrentUser->nobody->id
or $owner_id == $self->current_user->id )
{
$args->{'group_id'}{'valid_values'} = [
{ display => (($record->group_id ? $record->group->name : "Personal" ) . " (Unchanged)"),
value => $record->group_id,
},
{ display => 'Personal',
value => 0,
},
{ display_from => 'name',
value_from => 'id',
collection => Jifty->web->current_user->user_object->groups,
},
];
}
}
...
return $args;
}
--
More information about the jifty-devel
mailing list