diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 3b075c060..91aeac214 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -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'); + } } }); }); diff --git a/src/registrar/forms/domain.py b/src/registrar/forms/domain.py index 66ad3e8c1..e9f756acb 100644 --- a/src/registrar/forms/domain.py +++ b/src/registrar/forms/domain.py @@ -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 diff --git a/src/registrar/templates/django/forms/widgets/combobox.html b/src/registrar/templates/django/forms/widgets/combobox.html index ce4b384cc..c338953ed 100644 --- a/src/registrar/templates/django/forms/widgets/combobox.html +++ b/src/registrar/templates/django/forms/widgets/combobox.html @@ -1,3 +1,3 @@ -
+
{% include "django/forms/widgets/select.html" %}
\ No newline at end of file diff --git a/src/registrar/templates/domain_suborganization.html b/src/registrar/templates/domain_suborganization.html index f318af941..ed0cb69f3 100644 --- a/src/registrar/templates/domain_suborganization.html +++ b/src/registrar/templates/domain_suborganization.html @@ -15,6 +15,7 @@ If you believe there is an error please contact help@get.gov.

+ {% include "includes/required_fields.html" %}
{% csrf_token %} {% input_with_errors form.sub_organization %}