Changeset 7845
- Timestamp:
- 07/06/08 06:00:58 (5 months ago)
- Files:
-
- django/trunk/docs/newforms.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/newforms.txt
r7838 r7845 1818 1818 you to capture those definitions as a custom widget. 1819 1819 1820 For example, if you find that you are including a lot of comment fields on forms,1821 you could capture the idea of a ``TextInput`` with a specific ``size`` attribute 1822 as a custom extension to the ``TextInput`` widget::1820 For example, if you find that you are including a lot of comment fields on 1821 forms, you could capture the idea of a ``TextInput`` with a specific 1822 default ``size`` attribute as a custom extension to the ``TextInput`` widget:: 1823 1823 1824 1824 class CommentWidget(forms.TextInput): 1825 1825 def __init__(self, *args, **kwargs): 1826 kwargs.setdefault('attrs',{}).update({'size': '40'}) 1826 attrs = kwargs.setdefault('attrs',{}) 1827 if 'size' not in attrs: 1828 attrs['size'] = 40 1827 1829 super(CommentWidget, self).__init__(*args, **kwargs) 1830 1831 We allow the ``size`` attribute to be overridden by the user, but, by default, 1832 this widget will behave as if ``attrs={'size': 40}`` was always passed into the 1833 constructor. 1828 1834 1829 1835 Then you can use this widget in your forms::
