#27263: Allow validators to short-circuit in form field validation ---------------------------------+----------------------------------------- Reporter: Alexey Rogachev | Owner: nobody Type: New feature | Status: new Component: Forms | Version: master Severity: Normal | Resolution: Keywords: form, validator | Triage Stage: Someday/Maybe Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ---------------------------------+-----------------------------------------
Comment (by Alexey Rogachev): What about adding additional kwarg to `Field` in `django.forms.fields` called for example `show_circuit_validation`: {{{#!python def __init__(self, required=True, widget=None, label=None, initial=None, help_text='', error_messages=None, show_hidden_initial=False, validators=(), show_circuit_validation=False, localize=False, disabled=False, label_suffix=None): }}} And apply according changes in `run_validators` method: {{{#!python def run_validators(self, value): if value in self.empty_values: return errors = [] for v in self.validators: try: v(value) except ValidationError as e: if hasattr(e, 'code') and e.code in self.error_messages: e.message = self.error_messages[e.code] # Change start if self.short_circuit_validation: raise ValidationError(e.error_list) else: errors.extend(e.error_list) # Change end if errors: raise ValidationError(errors) }}} Not sure about default value for that argument, in my opinion it should be `True`. -- Ticket URL: <https://code.djangoproject.com/ticket/27263#comment:7> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.086c589babc767ed1ec8a1d24bc8e023%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.