Django

Code

Changeset 3792

Show
Ignore:
Timestamp:
09/22/06 07:46:35 (2 years ago)
Author:
mtredinnick
Message:

Documented the always_test attribute for validator functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/forms.txt

    r3774 r3792  
    482482to put punctuation at the end of your validation messages. 
    483483 
     484When Are Validators Called? 
     485--------------------------- 
     486 
     487After a form has been submitted, Django first checks to see that all the 
     488required fields are present and non-empty. For each field that passes that 
     489test *and if the form submission contained data* for that field, all the 
     490validators for that field are called in turn. The emphasised portion in the 
     491last sentence is important: if a form field is not submitted (because it 
     492contains no data -- which is normal HTML behaviour), the validators are not 
     493run against the field. 
     494 
     495This feature is particularly important for models using 
     496``models.BooleanField`` or custom manipulators using things like 
     497``forms.CheckBoxField``. If the checkbox is not selected, it will not 
     498contribute to the form submission. 
     499 
     500If you would like your validator to *always* run, regardless of whether the 
     501field it is attached to contains any data, set the ``always_test`` attribute 
     502on the validator function. For example:: 
     503 
     504    def my_custom_validator(field_data, all_data): 
     505        # ... 
     506 
     507    my_custom_validator.always_test = True 
     508 
     509This validator will always be executed for any field it is attached to. 
     510 
    484511Ready-made Validators 
    485512---------------------