Add a CSS class on required fields labels
This makes it possible to add a ' *' required notifier to labels without needing a bunch of custom form code in templates.
This commit is contained in:
parent
03c7633169
commit
189abf3e23
2 changed files with 34 additions and 0 deletions
|
@ -8,6 +8,8 @@ from django.db.models import Q
|
|||
|
||||
class ApplyCreditNoteForm(forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
def __init__(self, user, *a, **k):
|
||||
''' User: The user whose invoices should be made available as
|
||||
choices. '''
|
||||
|
@ -51,6 +53,8 @@ class ApplyCreditNoteForm(forms.Form):
|
|||
|
||||
class CancellationFeeForm(forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
percentage = forms.DecimalField(
|
||||
required=True,
|
||||
min_value=0,
|
||||
|
@ -60,6 +64,8 @@ class CancellationFeeForm(forms.Form):
|
|||
|
||||
class ManualCreditNoteRefundForm(forms.ModelForm):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
class Meta:
|
||||
model = commerce.ManualCreditNoteRefund
|
||||
fields = ["reference"]
|
||||
|
@ -67,6 +73,8 @@ class ManualCreditNoteRefundForm(forms.ModelForm):
|
|||
|
||||
class ManualPaymentForm(forms.ModelForm):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
class Meta:
|
||||
model = commerce.ManualPayment
|
||||
fields = ["reference", "amount"]
|
||||
|
@ -150,6 +158,9 @@ class _HasProductsFields(object):
|
|||
|
||||
|
||||
class _ProductsForm(_HasProductsFields, forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
@ -312,6 +323,8 @@ class _ItemQuantityProductsForm(_ProductsForm):
|
|||
|
||||
class _ItemQuantityProductsFormSet(_HasProductsFields, forms.BaseFormSet):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
@classmethod
|
||||
def set_fields(cls, category, products):
|
||||
raise ValueError("set_fields must be called on the underlying Form")
|
||||
|
@ -377,6 +390,9 @@ class _ItemQuantityProductsFormSet(_HasProductsFields, forms.BaseFormSet):
|
|||
|
||||
|
||||
class VoucherForm(forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
voucher = forms.CharField(
|
||||
label="Voucher code",
|
||||
help_text="If you have a voucher code, enter it here",
|
||||
|
@ -416,6 +432,9 @@ def staff_products_formset_factory(user):
|
|||
|
||||
|
||||
class InvoicesWithProductAndStatusForm(forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
invoice = forms.ModelMultipleChoiceField(
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
queryset=commerce.Invoice.objects.all(),
|
||||
|
|
|
@ -16,6 +16,9 @@ def mix_form(*a):
|
|||
|
||||
|
||||
class DiscountForm(forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
discount = forms.ModelMultipleChoiceField(
|
||||
queryset=conditions.DiscountBase.objects.all(),
|
||||
required=False,
|
||||
|
@ -23,6 +26,9 @@ class DiscountForm(forms.Form):
|
|||
|
||||
|
||||
class ProductAndCategoryForm(forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
product = forms.ModelMultipleChoiceField(
|
||||
queryset=inventory.Product.objects.select_related("category"),
|
||||
required=False,
|
||||
|
@ -34,6 +40,9 @@ class ProductAndCategoryForm(forms.Form):
|
|||
|
||||
|
||||
class UserIdForm(forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
user = forms.IntegerField(
|
||||
label="User ID",
|
||||
required=False,
|
||||
|
@ -41,6 +50,9 @@ class UserIdForm(forms.Form):
|
|||
|
||||
|
||||
class ProposalKindForm(forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
kind = forms.ModelMultipleChoiceField(
|
||||
queryset=proposals_models.ProposalKind.objects.all(),
|
||||
required=False,
|
||||
|
@ -48,6 +60,9 @@ class ProposalKindForm(forms.Form):
|
|||
|
||||
|
||||
class GroupByForm(forms.Form):
|
||||
|
||||
required_css_class = 'label-required'
|
||||
|
||||
GROUP_BY_CATEGORY = "category"
|
||||
GROUP_BY_PRODUCT = "product"
|
||||
|
||||
|
|
Loading…
Reference in a new issue