Placeholder, the class is not set when they tried to apply it through the django attrs specifier for forms.DateInput
ModelForm Form.
And according to docs
Accepts the same arguments as TextInput, with another optional argument:
Here is the code:
widgets = { 'my_date_field': forms.DateInput(format=('%d-%m-%Y'), attrs={'class':'myDateClass', 'placeholder':'Select a date'} ) }
The same applies for forms.TextInput
, and it works fine.
What am I missing here?
Someone just needs the full class code:
class trademark_form(ModelForm): my_date_field = DateField(input_formats=['%d-%m-%Y']) class Meta: model = myModel widgets = { 'my_date_field': forms.DateInput(format=('%d-%m-%Y'), attrs={'class':'myDateClass', 'placeholder':'Select a date'}), 'field1': forms.TextInput(attrs={'class':'textInputClass', 'placeholder':'Enter a Value..'}), 'field2': forms.TextInput(attrs={'class':'textInputClass', 'placeholder':'Enter a Value..', 'readonly':'readonly', 'value':10}), 'desc': forms.Textarea(attrs={'class':'textAreaInputClass', 'placeholder':'Enter desc', 'rows':5}), } exclude = ('my_valid_field')
The generated HTML for the field, my_date_field
:
<input type="text" id="id_my_date_field" name="my_date_field">
The generated HTML for the field, field1
:
<input type="text" name="field1" class="textInputClass" placeholder="Enter a Value.." id="id_field1">