Loading ...
Sorry, an error occurred while loading the content.
 

Re: [Cheetahtemplate-discuss] List of countries: Best way of preselecting a value?

Expand Messages
  • Gambit
    Thanks for the reply, ... No framework, this is just a very simple cgi application ... Thanks for the pointer. That was pretty much what I was doing in Python,
    Message 1 of 4 , Mar 2, 2007
      Thanks for the reply,

      > Which web framework are you using? Many frameworks have a select
      > widget that contains the options and the chosen value, and has a
      > render method to convert it all to HTML.

      No framework, this is just a very simple cgi application

      > Otherwise you can write a #def method that takes a list of options and
      > the currently-chosen option, and uses a #for loop to compose the HTML.

      Thanks for the pointer. That was pretty much what I was doing in Python,
      It worked in the first try:

      #def select($default_choice)

      <select id="country" name="country" size ="1" />

      #set $countries = [('AF', 'Afghanistan'), ('AL', 'Albania'), ('DZ',
      'Algeria'), ('AS','American Samoa')]

      #for $c in $countries

      #if $c[0] == $default_choice
      <option value="$c[0]" selected="selected">$c[1]</option>
      #else
      <option value="$c[0]">$c[1]</option>
      #end if

      #end for

      </select>

      #end def

      $select($default_choice)


      So is this the recommended method of achieving this (other than using a
      framework)?



      -------------------------------------------------------------------------
      Take Surveys. Earn Cash. Influence the Future of IT
      Join SourceForge.net's Techsay panel and you'll get the chance to share your
      opinions on IT & business topics through brief surveys-and earn cash
      http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Mike Orr
      ... That works. I would eliminate Python verbosity in the template by setting $countries in Python and passing it to the searchList. You can also make a
      Message 2 of 4 , Mar 2, 2007
        On 3/2/07, Gambit <gambit@...> wrote:
        > Thanks for the reply,
        >
        > > Which web framework are you using? Many frameworks have a select
        > > widget that contains the options and the chosen value, and has a
        > > render method to convert it all to HTML.
        >
        > No framework, this is just a very simple cgi application
        >
        > > Otherwise you can write a #def method that takes a list of options and
        > > the currently-chosen option, and uses a #for loop to compose the HTML.
        >
        > Thanks for the pointer. That was pretty much what I was doing in Python,
        > It worked in the first try:
        >
        > #def select($default_choice)
        >
        > <select id="country" name="country" size ="1" />
        >
        > #set $countries = [('AF', 'Afghanistan'), ('AL', 'Albania'), ('DZ',
        > 'Algeria'), ('AS','American Samoa')]
        >
        > #for $c in $countries
        >
        > #if $c[0] == $default_choice
        > <option value="$c[0]" selected="selected">$c[1]</option>
        > #else
        > <option value="$c[0]">$c[1]</option>
        > #end if
        >
        > #end for
        >
        > </select>
        >
        > #end def
        >
        > $select($default_choice)
        >
        >
        > So is this the recommended method of achieving this (other than using a
        > framework)?

        That works. I would eliminate Python verbosity in the template by
        setting $countries in Python and passing it to the searchList. You
        can also make a generic 'selected' method that takes a boolean
        expression and returns the selected attribute if true or nothing if
        false.

        --
        Mike Orr <sluggoster@...>

        -------------------------------------------------------------------------
        Take Surveys. Earn Cash. Influence the Future of IT
        Join SourceForge.net's Techsay panel and you'll get the chance to share your
        opinions on IT & business topics through brief surveys-and earn cash
        http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      Your message has been successfully submitted and would be delivered to recipients shortly.