mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 21:19:42 +02:00
Required fields
This commit is contained in:
parent
113421e0b8
commit
7f36e6270c
4 changed files with 13 additions and 6 deletions
|
@ -1965,11 +1965,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
// Find the selected option
|
// Find the selected option
|
||||||
const selectedOption = select.querySelector('option[selected]');
|
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) {
|
if (selectedOption) {
|
||||||
|
// 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;
|
input.value = selectedOption.textContent;
|
||||||
comboBox.classList.add('usa-combo-box--pristine');
|
comboBox.classList.add('usa-combo-box--pristine');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
|
@ -513,7 +513,7 @@ class DomainSuborganizationForm(forms.ModelForm):
|
||||||
|
|
||||||
sub_organization = forms.ModelChoiceField(
|
sub_organization = forms.ModelChoiceField(
|
||||||
queryset=Suborganization.objects.none(),
|
queryset=Suborganization.objects.none(),
|
||||||
required=False,
|
required=True,
|
||||||
widget=forms.Select(),
|
widget=forms.Select(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -525,7 +525,6 @@ class DomainSuborganizationForm(forms.ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields["sub_organization"].required = False
|
|
||||||
if self.instance and self.instance.portfolio:
|
if self.instance and self.instance.portfolio:
|
||||||
self.fields['sub_organization'].queryset = Suborganization.objects.filter(
|
self.fields['sub_organization'].queryset = Suborganization.objects.filter(
|
||||||
portfolio=self.instance.portfolio
|
portfolio=self.instance.portfolio
|
||||||
|
|
|
@ -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" %}
|
{% include "django/forms/widgets/select.html" %}
|
||||||
</div>
|
</div>
|
|
@ -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>.
|
If you believe there is an error please contact <a href="mailto:help@get.gov" class="usa-link">help@get.gov</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
{% include "includes/required_fields.html" %}
|
||||||
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
|
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% input_with_errors form.sub_organization %}
|
{% input_with_errors form.sub_organization %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue