forked from CGM_Public/pretix_original
Plugin API: Allow to add validators to checkout form fields
This commit is contained in:
@@ -98,12 +98,16 @@ class BaseQuestionsViewMixin:
|
|||||||
question_field.initial = overrides[question_field.question.identifier]['initial']
|
question_field.initial = overrides[question_field.question.identifier]['initial']
|
||||||
if 'disabled' in overrides[question_field.question.identifier]:
|
if 'disabled' in overrides[question_field.question.identifier]:
|
||||||
question_field.disabled = overrides[question_field.question.identifier]['disabled']
|
question_field.disabled = overrides[question_field.question.identifier]['disabled']
|
||||||
|
if 'validators' in overrides[question_field.question.identifier]:
|
||||||
|
question_field.validators += overrides[question_field.question.identifier]['validators']
|
||||||
else:
|
else:
|
||||||
if question_name in overrides:
|
if question_name in overrides:
|
||||||
if 'initial' in overrides[question_name]:
|
if 'initial' in overrides[question_name]:
|
||||||
question_field.initial = overrides[question_name]['initial']
|
question_field.initial = overrides[question_name]['initial']
|
||||||
if 'disabled' in overrides[question_name]:
|
if 'disabled' in overrides[question_name]:
|
||||||
question_field.disabled = overrides[question_name]['disabled']
|
question_field.disabled = overrides[question_name]['disabled']
|
||||||
|
if 'validators' in overrides[question_name]:
|
||||||
|
question_field.validators += overrides[question_name]['validators']
|
||||||
|
|
||||||
if len(form.fields) > 0:
|
if len(form.fields) > 0:
|
||||||
formlist.append(form)
|
formlist.append(form)
|
||||||
|
|||||||
@@ -498,6 +498,8 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
|||||||
for fname, val in overrides.items():
|
for fname, val in overrides.items():
|
||||||
if 'disabled' in val and fname in f.fields:
|
if 'disabled' in val and fname in f.fields:
|
||||||
f.fields[fname].disabled = val['disabled']
|
f.fields[fname].disabled = val['disabled']
|
||||||
|
if 'validators' in val and fname in f.fields:
|
||||||
|
f.fields[fname].validators += val['validators']
|
||||||
|
|
||||||
return f
|
return f
|
||||||
|
|
||||||
@@ -564,6 +566,8 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
|||||||
for fname, val in overrides.items():
|
for fname, val in overrides.items():
|
||||||
if 'disabled' in val and fname in f.fields:
|
if 'disabled' in val and fname in f.fields:
|
||||||
f.fields[fname].disabled = val['disabled']
|
f.fields[fname].disabled = val['disabled']
|
||||||
|
if 'validators' in val and fname in f.fields:
|
||||||
|
f.fields[fname].validators += val['validators']
|
||||||
|
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|||||||
@@ -229,8 +229,8 @@ contact_form_fields_overrides = EventPluginSignal(
|
|||||||
This signal allows you to override fields of the contact form that is presented during checkout
|
This signal allows you to override fields of the contact form that is presented during checkout
|
||||||
and by default only asks for the email address. It is also being used for the invoice address
|
and by default only asks for the email address. It is also being used for the invoice address
|
||||||
form. You are supposed to return a dictionary of dictionaries with globally unique keys. The
|
form. You are supposed to return a dictionary of dictionaries with globally unique keys. The
|
||||||
value-dictionary should contain one or more of the following keys: ``initial``, ``disabled``. The
|
value-dictionary should contain one or more of the following keys: ``initial``, ``disabled``,
|
||||||
key of the dictionary should be the name of the form field.
|
``validators``. The key of the dictionary should be the name of the form field.
|
||||||
|
|
||||||
As with all plugin signals, the ``sender`` keyword argument will contain the event. A ``request``
|
As with all plugin signals, the ``sender`` keyword argument will contain the event. A ``request``
|
||||||
argument will contain the request object. The ``order`` argument is ``None`` during the checkout
|
argument will contain the request object. The ``order`` argument is ``None`` during the checkout
|
||||||
@@ -260,8 +260,9 @@ question_form_fields_overrides = EventPluginSignal(
|
|||||||
This signal allows you to override fields of the questions form that is presented during checkout
|
This signal allows you to override fields of the questions form that is presented during checkout
|
||||||
and by default only asks for the questions configured in the backend. You are supposed to return a
|
and by default only asks for the questions configured in the backend. You are supposed to return a
|
||||||
dictionary of dictionaries with globally unique keys. The value-dictionary should contain one or
|
dictionary of dictionaries with globally unique keys. The value-dictionary should contain one or
|
||||||
more of the following keys: ``initial``, ``disabled``. The key of the dictionary should not be the
|
more of the following keys: ``initial``, ``disabled``, ``validators``. The key of the dictionary
|
||||||
question's form field name (``question_n``) but rather the questions ``identifier``.
|
should be the form field name for system fields (e.g. ``company``), or the question's ``identifier``
|
||||||
|
for user-defined questions.
|
||||||
|
|
||||||
The ``position`` keyword argument will contain a ``CartPosition`` or ``OrderPosition`` object.
|
The ``position`` keyword argument will contain a ``CartPosition`` or ``OrderPosition`` object.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user