(note: this hasn't been changed since before T3, so you may want to change
line 3 in
web2conf/models/db.py  to:

from applications.t3.modules.t2 import T2, COUNTRIES


before you run it locally.

Regards,
Yarko

On Sun, Dec 14, 2008 at 6:11 PM, Yarko Tymciurak <[email protected]> wrote:

> ummm.... you might try the "easy" way -
> add something like:
>
> db.tablename.field.comment=T('(required)')
>
> Take a look at how Massimo does this (and how it looks) in the regstration
> form for PyCon Registration -
>
> http://launchpad.net/web2conf
>
> Regards,
> Yarko
>
> On Sun, Dec 14, 2008 at 5:28 PM, Fran <[email protected]> wrote:
>
>>
>> I want to be able to flag to the user that certain input fields are
>> 'Required' (even before they hit 'Submit' & see the form failing to
>> validate)
>>
>> To do this I decided to try & create a widget that would append to the
>> normal INPUT box a SPAN(_class="req").
>> I can then use CSS/JS to populate that span with a red asterisk (but
>> keep it cutomisable by designers, if they wish).
>>
>> I followed the instructions here:
>> http://mdp.cti.depaul.edu/AlterEgo/default/show/170
>>
>> Copying the default from sqlhtml.py +125, I added this widget to my
>> customised T2 class:
>> def input_required_widget(field,value):
>>    items=[DIV(INPUT(_type='text',
>> _id=field_id,_class=field.type,_name=fieldname,value=str
>> (default),requires=field.requires),SPAN(_class='req'))]
>>    return DIV(*items)
>>
>> I then added this to my model:
>> db.cr_shelter.name.widget=t2.input_required_widget
>>
>> This gives the following error:
>> Traceback (most recent call last):
>>  File "C:\Bin\web2py\gluon\restricted.py", line 62, in restricted
>>    exec ccode in environment
>>  File "C:\Bin\web2py\applications\sahana/controllers/cr.py", line 78,
>> in <module>
>>  File "C:\Bin\web2py\gluon\globals.py", line 55, in <lambda>
>>    self._caller=lambda f: f()
>>  File "C:\Bin\web2py\applications\sahana/controllers/cr.py", line 40,
>> in add_shelter
>>    form=t2.create(db.cr_shelter)
>>  File "C:\Bin\web2py\applications\sahana\modules\t2.py", line 414, in
>> create
>>    showid=False,col3=col3,_class='t2-create')
>>  File "C:\Bin\web2py\gluon\sqlhtml.py", line 89, in __init__
>>    inp=field.widget(field,default)
>> TypeError: input_required_widget() takes exactly 2 arguments (3 given)
>>
>>
>> I searched around to see if there were other docs & found this:
>>
>> http://groups.google.com/group/web2py/browse_thread/thread/961d4303a7549241/a9d19abdfa4b6a07
>>
>> I tried bypassing the module & just put in a simple:
>> db.cr_shelter.name.widget=lambda self,value: DIV(INPUT
>> (_type='text'),SPAN(_class='req'))
>>
>> This displays correctly, but doesn't allow entered data to get stored
>> in the db, presumably because the id isn't set on the field.
>>
>> I tried to add all the fields in:
>> db.cr_shelter.name.widget=lambda self,value: DIV(INPUT(_type='text',
>> _id=field_id,_class=field.type,_name=fieldname,value=str
>> (default),requires=field.requires),SPAN(_class='req'))
>>
>> But then I get a scope problem:
>> Traceback (most recent call last):
>>  File "C:\Bin\web2py\gluon\restricted.py", line 62, in restricted
>>    exec ccode in environment
>>  File "C:\Bin\web2py\applications\sahana/controllers/cr.py", line 78,
>> in <module>
>>  File "C:\Bin\web2py\gluon\globals.py", line 55, in <lambda>
>>    self._caller=lambda f: f()
>>  File "C:\Bin\web2py\applications\sahana/controllers/cr.py", line 40,
>> in add_shelter
>>    form=t2.create(db.cr_shelter)
>>  File "C:\Bin\web2py\applications\sahana\modules\t2.py", line 414, in
>> create
>>    showid=False,col3=col3,_class='t2-create')
>>  File "C:\Bin\web2py\gluon\sqlhtml.py", line 89, in __init__
>>    inp=field.widget(field,default)
>>  File "C:\Bin\web2py\applications\sahana/models/db.py", line 517, in
>> <lambda>
>>    db.cr_shelter.name.widget=lambda self,value: DIV(INPUT
>> (_type='text', _id=field_id,_class=field.type,_name=fieldname,value=str
>> (default),requires=field.requires),SPAN(_class='req'))
>> NameError: global name 'field_id' is not defined
>>
>>
>> I changed my model to:
>> db.cr_shelter.name.widget=lambda self,value: t2.input_required_widget
>>
>> This gives no traceback, but instead of an INPUT box, I get the
>> following:
>> &lt;bound method T2SAHANA.input_required_widget of
>> &lt;applications.sahana.modules.sahana.T2SAHANA instance at
>> 0x04291698&gt;&gt;
>>
>> Trying:
>> db.cr_shelter.name.widget=lambda self,value: t2.input_required_widget
>> ('name')
>>
>> I'm back to the scope issue:
>> Traceback (most recent call last):
>>  File "C:\Bin\web2py\gluon\restricted.py", line 62, in restricted
>>    exec ccode in environment
>>  File "C:\Bin\web2py\applications\sahana/controllers/cr.py", line 78,
>> in <module>
>>  File "C:\Bin\web2py\gluon\globals.py", line 55, in <lambda>
>>    self._caller=lambda f: f()
>>  File "C:\Bin\web2py\applications\sahana/controllers/cr.py", line 40,
>> in add_shelter
>>    form=t2.create(db.cr_shelter)
>>  File "C:\Bin\web2py\applications\sahana\modules\t2.py", line 414, in
>> create
>>    showid=False,col3=col3,_class='t2-create')
>>  File "C:\Bin\web2py\gluon\sqlhtml.py", line 89, in __init__
>>    inp=field.widget(field,default)
>>  File "C:\Bin\web2py\applications\sahana/models/db.py", line 520, in
>> <lambda>
>>    db.cr_shelter.name.widget=lambda self,value:
>> t2.input_required_widget('name')
>>  File "C:\Bin\web2py\applications\sahana\modules\sahana.py", line
>> 163, in input_required_widget
>> NameError: global name 'field_id' is not defined
>>
>> This also happens even if I remove that global from my widget def:
>> items=[DIV(INPUT
>> (_type='text',_class=field.type,_name=field.name
>> ,value=value,requires=field.requires),SPAN
>> (_class='req'))]
>>
>> I'm not sure why there's a scope issue since my custom T2 has this
>> line:
>> from gluon.sqlhtml import *
>>
>>
>>
>> Searching some more:
>>
>> http://groups.google.com/group/web2py/browse_thread/thread/8f4ac3eb42b599f2/692bef480d3d5df9
>>
>> I tried this:
>> db.cr_shelter.name.widget=lambda a,b: t2.input_required_widget(a,b,
>> ['name'])
>> No joy:
>> TypeError: input_required_widget() takes exactly 2 arguments (4 given)
>>
>> I see that this widget has 3 arguments in it's def: (self,value,tags=
>> [])
>>
>> Since we only have 2, I tried:
>> db.cr_shelter.name.widget=lambda self,value: t2.input_required_widget
>> (self,value)
>> No joy:
>> TypeError: input_required_widget() takes exactly 2 arguments (3 given)
>>
>>
>> Going back to trying to fix the scope, I tried having this in the
>> widget def:
>> _id=gluon.sqlhtml.field_id
>> No joy:
>> NameError: global name 'field_id' is not defined
>>
>> Trying to see how T2's widgets deal with this I tried adding this to
>> the widget def:
>> field_id=self._tablename+'_'+self.name
>> No joy:
>> NameError: global name 'field_id' is not defined
>>
>>
>> I really need a helping hand here ;)
>>
>> Many thanks,
>> Fran.
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to