FAQ
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

Search Discussions

  • Benjamin Martin at Jun 22, 2010 at 7:59 am

    On 22/06/10 08:19, Hu Hailin 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...

    I am not 100% clear on what you want to do?... could you expand a little?
    Yes, it might be implemented using blocks but a little too complex.
    Any advice for implementing a repeatable hidden element?
    I have found the Repeatable element very useful, although abit combersum
    to use, what with the $el->repeat(x) .. but it works for me.

    Are you intending to use a single config file?...you might need to
    dynamically add the hidden elements when building the form.

    I guess you could put a delimited value in a hidden field but this seems
    like a rather hacky way to get multiple values into a hidden field.
  • Carl Franks at Jun 22, 2010 at 8:08 am
    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 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@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
  • Hu Hailin at Jun 22, 2010 at 8:45 am
    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 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 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@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu


    --
    islue
  • Carl Franks at Jun 22, 2010 at 9:19 am
    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 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 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 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@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu


    --
    islue

    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
  • Hu Hailin at Jun 22, 2010 at 9:51 am
    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 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 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 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 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@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu


    --
    islue

    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu


    --
    islue
  • Carl Franks at Jun 22, 2010 at 10:32 am
    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 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 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 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 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 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@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu


    --
    islue

    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu


    --
    islue

    _______________________________________________
    HTML-FormFu mailing list
    HTML-FormFu@lists.scsys.co.uk
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouphtml-formfu @
categoriesperl, catalyst
postedJun 22, '10 at 7:19a
activeJun 22, '10 at 10:32a
posts7
users3
websitemetacpan.org...

People

Translate

site design / logo © 2022 Grokbase