On 1/5/06, Kieren Diment <[EMAIL PROTECTED]> wrote:
>
> On 5 Jan 2006, at 13:58, Kim Ryan wrote:
>
> > I have customised my search template to included selection lists for
> > common values. All works well, and correct results are retrieved.
> >
> > The only problem is that when the search results are presented,
> > the selection boxes have all reverted to their default option.
> >
>
>
> Check out the thread in  Maypole and Maypole-devel titled "Design
> flaw in default templates" from the 22nd of Dec 2005 that discusses a
> couple of approaches to this.
>
>

I did not see anything regarding retiaining selections in select boxes
in that discussion Kieren.  Can someone post a link?

I have the same problem as you Kim. I just wrot a macro to
"set_selected" element to value. Here it is;

[%#

=head2 set_selected

Set which option in the select box element is selected based on value.
"element" is an HTML::Element object of type select.

=cut

%]

[% MACRO set_selected(element, value) BLOCK;
    FOR opt IN element.content_list;

        IF opt.attr('value') != value;
            opt.attr('selected', undef);
        ELSIF opt.attr('value') == value;;
            opt.attr('selected', 'selected');
            LAST;
        END;
    END;
END;
%]


I call this in search template *After* I put an empty option on the
top. HEre is snip from that.
[% SET element = classmetadata.cgi.$field; %]

<div class="row">
        <span class="label">[% "$name_prefix " IF name_prefix;
classmetadata.colnames.$field || field FILTER ucfirst; %]</span>
        [%  IF element.tag == "select";
                # unset selected element
                #FOR opt IN element.content_list;
                #   opt.attr('selected', undef) IF opt.attr('selected');
                #END;

                # put empty opt as top if we don't have one
                IF (element.content_list.0.content_list) ;
                    USE element_maker = Class("HTML::Element");
                    SET element = element.unshift_content(
                    element_maker.new("option", 'value', ""));
                END;

                # set the previous value
                IF cgi_params.exists(field);
                    set_selected(element, cgi_params.$field);
                END;

            END;
        %]


Let me know if you have questions.


>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Maypole-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/maypole-users
>


--
pjs


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Maypole-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-users

Reply via email to