mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-05 01:11:55 +02:00
Required fields
This commit is contained in:
parent
113421e0b8
commit
7f36e6270c
4 changed files with 13 additions and 6 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
|
@ -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 %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue