Required fields

This commit is contained in:
zandercymatics 2024-07-23 11:29:49 -06:00
parent 113421e0b8
commit 7f36e6270c
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 13 additions and 6 deletions

View file

@ -1965,10 +1965,17 @@ document.addEventListener('DOMContentLoaded', function() {
// Find the selected option
const selectedOption = select.querySelector('option[selected]');
// If there's a selected option, set its text as the input value
// If there's a selected option, set its text as the input value.
// If the default name is "------", then this indicates that the field is blank.
// Don't populate in this case.
if (selectedOption) {
input.value = selectedOption.textContent;
comboBox.classList.add('usa-combo-box--pristine');
// Check to make sure the value isn't just a line of dashes.
// Caveat: we can't have any suborgs named "------". This is OK.
const isEmptyValue = /^-+$/.test(selectedOption.textContent);
if (!isEmptyValue) {
input.value = selectedOption.textContent;
comboBox.classList.add('usa-combo-box--pristine');
}
}
});
});

View file

@ -513,7 +513,7 @@ class DomainSuborganizationForm(forms.ModelForm):
sub_organization = forms.ModelChoiceField(
queryset=Suborganization.objects.none(),
required=False,
required=True,
widget=forms.Select(),
)
@ -525,7 +525,6 @@ class DomainSuborganizationForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["sub_organization"].required = False
if self.instance and self.instance.portfolio:
self.fields['sub_organization'].queryset = Suborganization.objects.filter(
portfolio=self.instance.portfolio

View file

@ -1,3 +1,3 @@
<div class="usa-combo-box" data-initial-value="{{ widget.value }}">
<div class="usa-combo-box">
{% include "django/forms/widgets/select.html" %}
</div>

View file

@ -15,6 +15,7 @@
If you believe there is an error please contact <a href="mailto:help@get.gov" class="usa-link">help@get.gov</a>.
</p>
{% include "includes/required_fields.html" %}
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
{% csrf_token %}
{% input_with_errors form.sub_organization %}