[web2py] Re: Default value (Not in table) in Dropdown

2015-02-02 Thread Omi Chiba
Thanks. It worked great!!!

On Monday, February 2, 2015 at 4:07:36 PM UTC-6, Niphlod wrote:

 that's pretty obvious. look at what you're trying to render in the 
 view!


  {{for model in models:}}
 option value={{=model.Name}} 
 {{= selected='selected' if model.Name==request.vars.model_name else 
 }}
 {{=model.Name}}
 /option
 {{pass}}


 at the very least, if you want to keep the same code in the view, you 
 should have the controller pass a list with a Storage() that has a Name 
 attribute

 from gluon.storage import Storage
 models = [ Storage(Name='SELECT Model')  ]






-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Default value (Not in table) in Dropdown

2015-02-02 Thread Niphlod
building it by hand kinda slows things down a lot (boilerplate alert). 
Thankfully, we all know HTML, but bring!

Having a widget displaying a default value (that won't get accepted) is 
pretty damn easy with IS_IN_SET(..., zero='choose me...')

with html and the requirement of no added validation (both serverside or 
javascript), you can only do

selectoption selected disabledchoose one/optionoption value=1
/option/select

i.e. make the first option selected AND disabled. It will show up but the 
user won't be able to transmit it as part of the form, not even in 
javascript (val() of this select would be *null*)


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Default value (Not in table) in Dropdown

2015-02-02 Thread Niphlod
that's pretty obvious. look at what you're trying to render in the 
view!


 {{for model in models:}}
option value={{=model.Name}} 
{{= selected='selected' if model.Name==request.vars.model_name else 
}}
{{=model.Name}}
/option
{{pass}}


at the very least, if you want to keep the same code in the view, you 
should have the controller pass a list with a Storage() that has a Name 
attribute

from gluon.storage import Storage
models = [ Storage(Name='SELECT Model')  ]




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Default value (Not in table) in Dropdown

2015-02-02 Thread Omi Chiba
In my controller, can I just add the default value in controller something 
like below? If possible, this is the easiest one for me. Though I will get 
error I do this.


*controller*
   if request.vars.model_name: 
models = db(db.KR_Lead.ModelName == 
request.vars.model_name).select(db.KR_Lead.ALL)
else:
*models = 'SELECT Model'*

Error:
type 'exceptions.AttributeError'('str' object has no attribute 'Name')



On Monday, February 2, 2015 at 3:38:11 PM UTC-6, Niphlod wrote:

 building it by hand kinda slows things down a lot (boilerplate alert). 
 Thankfully, we all know HTML, but bring!

 Having a widget displaying a default value (that won't get accepted) is 
 pretty damn easy with IS_IN_SET(..., zero='choose me...')

 with html and the requirement of no added validation (both serverside or 
 javascript), you can only do

 selectoption selected disabledchoose one/optionoption value=1
 /option/select

 i.e. make the first option selected AND disabled. It will show up but the 
 user won't be able to transmit it as part of the form, not even in 
 javascript (val() of this select would be *null*)




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.