Mailing List Archive

HTML::FormHandler setting html attributes programatically in form class
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


_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: HTML::FormHandler setting html attributes programatically in form class [ In reply to ]
Hi,
I've solved this by encapsulating the logic in the form class, this way
it is testable completely decoupled from Catalyst.

Just access the passed object or define additional attributes in your
form class that are populated by the Catalyst app on instantiation.

With a before 'set_active' => sub {} Moose method modifier you can then
use add_active to activate deactivated fields (I've chosen that way round).

Cheers, Alex

On 2016-01-11 11:26, Hetényi Csaba wrote:
> 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
>
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/



*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: HTML::FormHandler setting html attributes programatically in form class [ In reply to ]
Dear Alex

Thanks for reply.
Yes, i know the "before 'set_active'" method, just don't know, how to
apply the new attributes to a field.
(especially the proper syntax)
for example: how to apply "element_attr => { readonly => 'readonly' }"
for a field in a sub.

Thank You!

2016.01.11. 14:43 keltezéssel, Hartmaier Alexander írta:
> Hi,
> I've solved this by encapsulating the logic in the form class, this way
> it is testable completely decoupled from Catalyst.
>
> Just access the passed object or define additional attributes in your
> form class that are populated by the Catalyst app on instantiation.
>
> With a before 'set_active' => sub {} Moose method modifier you can then
> use add_active to activate deactivated fields (I've chosen that way
> round).
>
> Cheers, Alex
>
> On 2016-01-11 11:26, Hetényi Csaba wrote:
>> 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
>>
>>
>> _______________________________________________
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive:
>> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
>
>
>
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
>
> T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
> Handelsgericht Wien, FN 79340b
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
>
> Notice: This e-mail contains information that is confidential and may
> be privileged.
> If you are not the intended recipient, please notify the sender and then
> delete this e-mail immediately.
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
>
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/


_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/