Ticket #16304: placeholder.patch
File placeholder.patch, 1.3 KB (added by , 13 years ago) |
---|
-
fields.py
179 179 return result 180 180 181 181 class CharField(Field): 182 def __init__(self, max_length=None, min_length=None, *args, **kwargs):183 self.max_length, self.min_length = max_length, min_length182 def __init__(self, max_length=None, min_length=None, placeholder=None, *args, **kwargs): 183 self.max_length, self.min_length, self.placeholder = max_length, min_length, placeholder 184 184 super(CharField, self).__init__(*args, **kwargs) 185 185 if min_length is not None: 186 186 self.validators.append(validators.MinLengthValidator(min_length)) … … 194 194 return smart_unicode(value) 195 195 196 196 def widget_attrs(self, widget): 197 attrs = {} 198 if self.placeholder is not None and isinstance(widget, TextInput): 199 attrs["placeholder"] = str(self.placeholder) 197 200 if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): 198 201 # The HTML attribute is maxlength, not max_length. 199 return {'maxlength': str(self.max_length)} 202 attrs['maxlength'] = str(self.max_length) 203 if attrs: 204 return attrs 200 205 201 206 class IntegerField(Field): 202 207 default_error_messages = {