[html-formfu] set multiple values to hidden element?

Carl Franks fireartist at gmail.com
Tue Jun 22 10:32:04 GMT 2010


Hi,

No problem,
Just be aware that if the form is then submitted and processed by
FormFu, you'd need to add those fields again *before* calling
$form->process() - so that the $form object has a field matching the
"name" of each submitted parameter.
Otherwise, the values will be ignored, and won't be available via
$form->params() or $form->param_value().

Carl


On 22 June 2010 10:51, Hu Hailin <i at h2l.name> wrote:
> Hi,
>
> Wow, I didn't know the part of that.
> How kind of you, Carl.
>
> Finally, I decided to add hidden fields dynamically in perl codes like this:
>
> my $form = $c->stash->{ form };
> my $position = $form->get_element({ type => 'Submit'});
> my @hidden = qw( foo bar );
> foreach my $hidden ( @hidden ) {
>  for ( $c->req->param( $hidden ) ) {
>    my $element = $form->element({ type => 'Hidden', name => $hidden,
> value=> $_ });
>    $form->insert_after( $element, $position );
>  }
> }
>
> I would build urls according to hidden fields' value using jQuery and
> I think multiple value field is easier to handle.
>
> Thank you all the same.
>
> On Tue, Jun 22, 2010 at 6:19 PM, Carl Franks <fireartist at gmail.com> wrote:
>> Hi,
>>
>> There's already a HTML::FormFu::Filter::Spit that can deserialize a
>> submitted value.
>> e.g, this will turn "a,b,c" into a perl array [ 'a', 'b', 'c' ].
>>    filter:
>>        - type: Split
>>          regex: ','
>>
>> It would be simple to write a custom Deflator that could do the
>> serialization for you...
>>
>> package MyApp::FormFu::Deflator::JoinIDs
>> use base 'HTML::FormFu::Deflator';
>> use HTML::FormFu::Constants qw( $EMPTY_STR );
>> use Try::Tiny;
>>
>> sub deflator {
>>    my ( $self, $value ) = @_;
>>
>>    return if !defined $value || $value eq $EMPTY_STR;
>>
>>    my $flat_value;
>>
>>    try {
>>        $flat_value = join ',', @$value;
>>    } catch {
>>        return $value;
>>    };
>>
>>    return $flat_value;
>> }
>> 1;
>>
>> If you add that deflator to the Hidden field, it would let you do:
>>    $field->default( \@department_ids );
>>
>> Carl
>>
>>
>> On 22 June 2010 09:45, Hu Hailin <i at h2l.name> wrote:
>>> Hi,
>>>
>>> Let me try to make an example:
>>>
>>> a employee search page and can be searched by department.
>>> Suppose there are hundreds of departments, showing a very long
>>> multiple selectable select element seems not a good idea.
>>> I try to make the page only take departments' id from query and
>>> display the departments' info in the page.
>>>
>>> Even if use a block element, hundreds of departments info have to be
>>> listed in page, right?
>>>
>>> Well, it seems I have to serialize data...
>>>
>>> Thank you, guys.
>>>
>>> On Tue, Jun 22, 2010 at 5:08 PM, Carl Franks <fireartist at gmail.com> wrote:
>>>> Hi,
>>>>
>>>> A hidden field won't support multiple values, so you'd need to
>>>> serialize them yourself - for example with JSON.
>>>>    $field->default( encode_json( $value ) );
>>>>
>>>> I'd recommend though, just using Block elements, as it's very easy to
>>>> attach IDs or class-names, which your JavaScript can target to
>>>> show/hide the blocks.
>>>>
>>>> Carl
>>>>
>>>>
>>>> On 22 June 2010 08:19, Hu Hailin <i at h2l.name> wrote:
>>>>> Hi
>>>>>
>>>>> My situation is that I have so large a form that I try to split some
>>>>> condition out to display them in a collapsible div with javascript.
>>>>> So I am trying to pass data using Element::Hidden, but it accepts
>>>>> first value and fills it in form in multiple values' case.
>>>>> I also glanced at Element::Repeatable which seems not the one I want...
>>>>>
>>>>> Yes, it might be implemented using blocks but a little too complex.
>>>>> Any advice for implementing a repeatable hidden element?
>>>>>
>>>>> Thanks.
>>>>> --
>>>>> islue
>>>>>
>>>>> _______________________________________________
>>>>> HTML-FormFu mailing list
>>>>> HTML-FormFu at lists.scsys.co.uk
>>>>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>>>>
>>>>
>>>> _______________________________________________
>>>> HTML-FormFu mailing list
>>>> HTML-FormFu at lists.scsys.co.uk
>>>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>>>
>>>
>>>
>>>
>>> --
>>> islue
>>>
>>> _______________________________________________
>>> HTML-FormFu mailing list
>>> HTML-FormFu at lists.scsys.co.uk
>>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>>
>>
>> _______________________________________________
>> HTML-FormFu mailing list
>> HTML-FormFu at lists.scsys.co.uk
>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>
>
>
>
> --
> islue
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>



More information about the HTML-FormFu mailing list