from django.forms import ModelForm from django import forms from .models import Invoice, InvoiceItemLine from crispy_forms.helper import FormHelper class InvoiceForm(ModelForm): class Meta: model = Invoice fields = "__all__" widgets = { 'TxnDate' : forms.DateInput(attrs={'type':"date"}), 'BillAddr1' : forms.Textarea(attrs={'rows':7, 'style':'height:180px'}), 'ShipAddr1' : forms.Textarea(attrs={'rows':7, 'style':'height:180px'}), 'TotalAmount' : forms.TextInput(attrs={'class':'text-end hidden', 'onkeypress':'return event.preventDefault()'}) } def __init__(self, *args, **kwargs): super(InvoiceForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) # self.helper.form_show_labels = False self.fields['TotalAmount'].label = False self.fields['TotalAmount'].field_class = '' class InvoiceItemLineForm(ModelForm): class Meta: model = InvoiceItemLine fields = ('ItemRefFullName', 'Desc', 'Quantity', 'UnitOfMeasure', 'Rate', 'Amount', 'Invoiced', 'LineIsManuallyClosed') # fields = "__all__" widgets = { # 'ItemRefFullName' : forms.Select(choices=[('1', '1')]), 'ItemRefFullName' : forms.NumberInput(attrs={'class':'hidden itemreffullname'}), 'Desc' : forms.TextInput(attrs={'class':'desc'}), 'Quantity' : forms.TextInput(attrs={'class':'quantity','onkeypress':'numberOnly(event)'}), #'onkeypress':'return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 46'}), 'UnitOfMeasure' : forms.Select(attrs={'class':'unitofmeasure'}), 'Rate' : forms.TextInput(attrs={'class':'rate text-end', 'onkeypress':'numberOnly(event)'}), 'Amount' : forms.TextInput(attrs={'class':'amount text-end', 'onkeypress':'numberOnly(event)', 'onchange':'amountchanged(event)'}), } def __init__(self, *args, **kwargs): super(InvoiceItemLineForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.form_show_labels = False # self.helper.form_class = "abc" # self.helper.field_class = "xyz" DEMO_CHOICES =( ("1", "Naveen"), ("2", "Pranav"), ("3", "Isha"), ("4", "Saloni"), ) class GeeksForm(forms.Form): geeks_field = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices = DEMO_CHOICES)