I have a problem with my field.
I have two field that have same field and widget. But one of the field didn’t show blank validation message.
Model:
class MagangLetter(models.Model):
to=models.CharField(max_length=255)
reason=models.CharField(max_length=255)
start_date=models.DateField()
end_date=models.DateField()
Form:
class MagangLetterForm(forms.ModelForm):
class Meta:
model=MagangLetter
fields=['to','reason','start_date','end_date']
widgets={
'to':forms.Textarea(attrs={'class':'form-control','rows':'3','placeholder':'''#example'''}),
'reason':forms.Textarea(attrs={'class':'form-control','rows':'3','placeholder':'''#example'''}),
'start_date':forms.DateInput(attrs={'class':'form-control','type':'date'}),
'end_date':forms.DateInput(attrs={'class':'form-control','type':'date'})
}
View
class CreateLetterMagang(CreateView):
model=MagangLetter
form_class=MagangLetterForm
template_name_suffix="_create_form"
def get_context_data(self, **kwargs):
context=super().get_context_data(**kwargs)
form:MagangLetter=context['form']
file_template=Template(services.letter.get_html_template('magang.docx'))
date=datetime.datetime.now()
day=settings.MONTHS[date.strftime('%m')]
file_context=Context({
'letter_number' : '........',
'date_submitted' : f'{date:%d} {day} {date:%Y}',
'to': form['to'],
'name': self.request.user.get_full_name(),
'nim': self.request.user.detail.id_number,
'reason':form['reason'],
'start_date': form['start_date'],
'end_date': form['end_date'],
'nip':'.............',
'dosen':'...............',
'sign': ''
})
html=file_template.render(file_context)
soup = BeautifulSoup(html, 'html.parser')
date_submit=soup.find(string=re.compile("Yogyakarta,"))
p=soup.find(string=re.compile("#test"))
date_submit.parent.parent['style']='width:15rem;'
p.parent['class']='p-0'
p=soup.find(string=re.compile("#test"))
p.parent['class']='p-0'
p=soup.find(string=re.compile("#test"))
p.parent['class']='p-0'
table=(p.next_element.next_element.next_element)
table['class'].append('text-center ms-auto')
table['style']='width:fit-content'
date_forms=soup.find_all(type='date')
for date_form in date_forms:
date_form['class'].append('w-25')
date_form['style']='min-width:fit-content;'
context['docx']=soup.prettify()
return context
Template:
{% block body %}
<div class="row content d-block overflow-auto">
<div class="card p-3" style="width:40rem;">
<form method='post'>
{% csrf_token %}
{{docx|safe}}
<input type='submit' class='btn btn-primary' value='Buat Surat'></input>
</form>
</div>
</div>
{% endblock body %}
to
field not showing validation message.
reason
field showing validation message.
How do I show this validation on both field?