#2352: Provide widget instance to callable default value
-------------------------+--------------------------------------------------
 Reporter:  xaka         |        Owner:       
     Type:  enhancement  |       Status:  new  
 Priority:  normal       |    Milestone:       
Component:  TurboGears   |      Version:  1.0.8
 Severity:  normal       |   Resolution:       
 Keywords:               |  
-------------------------+--------------------------------------------------
Comment (by chrisz):

 Replying to [comment:3 xaka]:
 > What you will do if you need return default value depend on field
 properties (name, params, something other)?

 As explained above: Instead of {{{return "Bozo"}}} you could write
 something like {{{return self.fields[0].name}}}. The advantage here is
 that you can also refer to parameters of other fields that way. Or you can
 do the following if you only need parameters of the field itself:

 {{{
 class MyTextField(widgets.TextField):

     def default(self):
         return get_value_from_db(self.name)


 class MyForm(widgets.TableForm):

     fields = [MyTextField(name='bozo')]

 myform=MyForm()
 }}}

 Btw, do you want to use this trick to prepopulate the fields of a form
 with values from the database? This is much easier. You just pass the
 widget at render time the object from the database. No need to use default
 values for this. These come into play when you display a form to enter a
 new database record and are usually pretty static.

-- 
Ticket URL: <http://trac.turbogears.org/ticket/2352#comment:4>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to