Ticket #16304: 16304.patch
File 16304.patch, 3.9 KB (added by , 13 years ago) |
---|
-
docs/ref/models/fields.txt
377 377 378 378 .. note:: 379 379 380 If you are using HTML5 templates and wish to have a placeholder attribute 381 in your input box, supply a placeholder attribute containing a string when 382 creating your model fields. Using :doc:`Model Forms 383 </topics/forms/modelforms>` will automatically take care of the 384 placeholder attribute. Refer :doc:`Form Fields </ref/forms/fields>` when 385 creating your own forms. 386 387 .. note:: 388 380 389 If you are writing an application that must be portable to multiple 381 390 database backends, you should be aware that there are restrictions on 382 391 ``max_length`` for some backends. Refer to the :doc:`database backend -
docs/ref/forms/fields.txt
330 330 If provided, these arguments ensure that the string is at most or at least 331 331 the given length. 332 332 333 .. note:: 334 335 If you are using HTML5 templates, you can pass a placeholder attribute 336 containg a string, which will act as the placeholder for the resulting 337 input box. 338 333 339 ``ChoiceField`` 334 340 ~~~~~~~~~~~~~~~ 335 341 -
django/db/models/fields/__init__.py
79 79 serialize=True, unique_for_date=None, unique_for_month=None, 80 80 unique_for_year=None, choices=None, help_text='', db_column=None, 81 81 db_tablespace=None, auto_created=False, validators=[], 82 error_messages=None ):82 error_messages=None, placeholder=None): 83 83 self.name = name 84 84 self.verbose_name = verbose_name 85 85 self.primary_key = primary_key … … 102 102 self.db_column = db_column 103 103 self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE 104 104 self.auto_created = auto_created 105 self.placeholder = placeholder 105 106 106 107 # Set db_index to True if the field has a relationship and doesn't 107 108 # explicitly set db_index. … … 622 623 # will be validated twice. This is considered acceptable since we want 623 624 # the value in the form field (to pass into widget for example). 624 625 defaults = {'max_length': self.max_length} 626 if self.placeholder: 627 defaults.update({'placeholder': self.placeholder}) 625 628 defaults.update(kwargs) 626 629 return super(CharField, self).formfield(**defaults) 627 630 -
django/forms/fields.py
182 182 return result 183 183 184 184 class CharField(Field): 185 def __init__(self, max_length=None, min_length=None, *args, **kwargs): 186 self.max_length, self.min_length = max_length, min_length 185 def __init__(self, max_length=None, min_length=None, placeholder=None, 186 *args, **kwargs): 187 self.max_length, self.min_length, self.placeholder = (max_length, 188 min_length, placeholder) 187 189 super(CharField, self).__init__(*args, **kwargs) 188 190 if min_length is not None: 189 191 self.validators.append(validators.MinLengthValidator(min_length)) … … 201 203 if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): 202 204 # The HTML attribute is maxlength, not max_length. 203 205 attrs.update({'maxlength': str(self.max_length)}) 206 if self.placeholder and isinstance(widget, TextInput): 207 attrs.update({'placeholder': str(self.placeholder)}) 204 208 return attrs 205 209 206 210 class IntegerField(Field):