[Catalyst] HTML::FormHandler setting html attributes programatically in form class

Hetényi Csaba csabiwork at tata.hu
Mon Jan 11 10:26:20 GMT 2016


Dear Friends

Please, forgive me, i know, this is not a HTML::FormHandler related 
list, but i hope, there are a lot of people here who use it!

In a catalyst app, i'd like to disable (make the field readonly and 
disabled but not inactive) a form field based on a value (if user has 
the role, or not).
If i set "hardwired" in the form class:

> has_field 'foo' => ( type => 'Text', element_attr => { readonly => 
> 'readonly' }, disabled => 1 );

works perfectly.

But i'd like to apply the readonly/disabled attributes based on a 
boolean value in form class.

I see, there is a "html_attributes callback" but don't know, how to use it:
> sub html_attributes {
>     my ( $self, $obj, $type, $attrs, $result ) = @_;
>     # obj is either form or field
>     $attrs->{class} = 'label' if $type eq 'label';
>     $attrs->{placeholder} = $self->_localize($attrs->{placeholder})
>         if exists $attrs->{placeholder};
>     return $attrs;
> }

Thank You in advance!
Csabi




More information about the Catalyst mailing list