[web2py] REF: Setting the selected option attribute

2012-12-31 Thread Teddy Nyambe
Happy New Year!!

I am trying to set some functions...am having trouble haveing a selected
option, am doing as follows:

def get_drop_down_option9(options_dict, selected):
  return [OPTION(value_, _value=key_ , *['_selected' if selected == key_
else '']) for key_, value_ in options_dict.iteritems()]

I am getting the output

print SELECT(get_drop_down_option9(options, 'dad'))

selectoption value=dadJame_selected/optionoption
value=sisterAnn/optionoption value=bro1Sam/optionoption
value=momSara/optionoption value=bro2Kelvin/option/select


What am i missing or how do i get it right

-- 
...
Teddy Lubasi Nyambe
Opensource Zambia
Lusaka, ZAMBIA

Cell: +260 97 7760473
website: http://www.opensource.org.zm

~/
Human Knowledge belongs to the world! - AntiTrust

Man is a tool-using animal. Without tools he is nothing, with tools he is
all - Thomas Carlyle 1795-1881

/~

-- 





Re: [web2py] REF: Setting the selected option attribute

2012-12-31 Thread Bruno Rocha
On Mon, Dec 31, 2012 at 1:21 PM, Teddy Nyambe software@gmail.comwrote:

 def get_drop_down_option9(options_dict, selected):
   return [OPTION(value_, _value=key_ , **{'_selected': 'selected'} if
 selected == key_ else {}) for key_, value_ in options_dict.iteritems()]


-- 





Re: [web2py] REF: Setting the selected option attribute

2012-12-31 Thread Teddy Nyambe
Excellent!!! Python + Web2py = Productivity Guaranteed!

On Mon, Dec 31, 2012 at 5:30 PM, Bruno Rocha rochacbr...@gmail.com wrote:

 def get_drop_down_option9(options_dict, selected):
   return [OPTION(value_, _value=key_ , **{'_selected': 'selected'} if
 selected == key_ else {}) for key_, value_ in options_dict.iteritems()]




-- 
...
Teddy Lubasi Nyambe
Opensource Zambia
Lusaka, ZAMBIA

Cell: +260 97 7760473
website: http://www.opensource.org.zm

~/
Human Knowledge belongs to the world! - AntiTrust

Man is a tool-using animal. Without tools he is nothing, with tools he is
all - Thomas Carlyle 1795-1881

/~

-- 





Re: [web2py] REF: Setting the selected option attribute

2012-12-31 Thread Anthony
Or you can do:

OPTION(value_, _value=key_, _selected=key_ == selected)

That will result in selected=selected when key_ == selected and no 
selected attribute in the HTML otherwise.

Even easier, though, is to let the SELECT helper handle this for you by 
specifying it's value argument (which automatically sets the option with 
that value as selected):

SELECT(get_drop_down_option9(options), value='dad')

In that case, you can simplify get_drop_down_options9() so it doesn't set 
the selected attribute, as that will be done by the SELECT helper.

Anthony

On Monday, December 31, 2012 10:30:38 AM UTC-5, rochacbruno wrote:



 On Mon, Dec 31, 2012 at 1:21 PM, Teddy Nyambe 
 softwa...@gmail.comjavascript:
  wrote:

 def get_drop_down_option9(options_dict, selected):
   return [OPTION(value_, _value=key_ , **{'_selected': 'selected'} if 
 selected == key_ else {}) for key_, value_ in options_dict.iteritems()]




-- 





Re: [web2py] REF: Setting the selected option attribute

2012-12-31 Thread Bruno Rocha
+1

Anthony should write a web2py tips and secrets book :)

-- 





Re: [web2py] REF: Setting the selected option attribute

2012-12-31 Thread Anthony
:-)

The first one I think is a bit of a secret, but the second one is actually 
in the book.

On Monday, December 31, 2012 10:53:32 AM UTC-5, rochacbruno wrote:

 +1

 Anthony should write a web2py tips and secrets book :)


-- 





Re: [web2py] REF: Setting the selected option attribute

2012-12-31 Thread Teddy Nyambe
Very interesting!
On Dec 31, 2012 5:58 PM, Anthony abasta...@gmail.com wrote:

 :-)

 The first one I think is a bit of a secret, but the second one is actually
 in the book.

 On Monday, December 31, 2012 10:53:32 AM UTC-5, rochacbruno wrote:

 +1

 Anthony should write a web2py tips and secrets book :)

  --





--