﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7630	Example for custom widgets in newforms documentation is subtly wrong	Christian Tanzer <tanzer@…>	nobody	"The example given for a custom widget 

{{{
class CommentWidget(forms.TextInput):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('attrs',{}).update({'size': '40'})
        super(CommentWidget, self).__init__(*args, **kwargs)
}}}

will silently override further instance-specific customizations for size, e.g.,

{{{
comment = forms.CharField(
                widget=CommentWidget(attrs={'size': '80'}))
}}}

To avoid this, the example should be written like

{{{
class CommentWidget(forms.TextInput):
    def __init__(self, *args, **kwargs):
        attrs = kwargs.setdefault('attrs',{})
        if 'size' not in attrs :
            attrs['size'] = '40'
        super(CommentWidget, self).__init__(*args, **kwargs)
}}}

"		closed	Documentation	dev		fixed			Unreviewed	0	0	0	0	0	0
