mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-01 07:26:34 +02:00
refactored domain request form modal to remove hidden input
This commit is contained in:
parent
1c280905de
commit
76ebec01ce
6 changed files with 63 additions and 17 deletions
12
src/registrar/assets/src/js/getgov/domain-request-form.js
Normal file
12
src/registrar/assets/src/js/getgov/domain-request-form.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { submitForm } from './helpers.js';
|
||||
|
||||
export function initDomainRequestForm() {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const button = document.getElementById("domain-request-form-submit-button");
|
||||
if (button) {
|
||||
button.addEventListener("click", function () {
|
||||
submitForm("submit-domain-request-form");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
|
@ -75,3 +75,17 @@ export function debounce(handler, cooldown=600) {
|
|||
export function getCsrfToken() {
|
||||
return document.querySelector('input[name="csrfmiddlewaretoken"]').value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to submit a form
|
||||
* @param {} form_id - the id of the form to be submitted
|
||||
*/
|
||||
export function submitForm(form_id) {
|
||||
let form = document.getElementById(form_id);
|
||||
if (form) {
|
||||
console.log("submitting form");
|
||||
form.submit();
|
||||
} else {
|
||||
console.error("Form '" + form_id + "' not found.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import { initMembersTable } from './table-members.js';
|
|||
import { initMemberDomainsTable } from './table-member-domains.js';
|
||||
import { initEditMemberDomainsTable } from './table-edit-member-domains.js';
|
||||
import { initPortfolioNewMemberPageToggle, initAddNewMemberPageListeners, initPortfolioMemberPageRadio } from './portfolio-member-page.js';
|
||||
import { initDomainRequestForm } from './domain-request-form.js';
|
||||
|
||||
initDomainValidators();
|
||||
|
||||
|
@ -36,6 +37,8 @@ initMembersTable();
|
|||
initMemberDomainsTable();
|
||||
initEditMemberDomainsTable();
|
||||
|
||||
initDomainRequestForm();
|
||||
|
||||
// Init the portfolio new member page
|
||||
initPortfolioMemberPageRadio();
|
||||
initPortfolioNewMemberPageToggle();
|
||||
|
|
|
@ -130,9 +130,21 @@
|
|||
aria-describedby="Are you sure you want to submit a domain request?"
|
||||
data-force-action
|
||||
>
|
||||
{% include 'includes/modal.html' with is_domain_request_form=True review_form_is_complete=review_form_is_complete modal_heading=modal_heading|safe modal_description=modal_description|safe modal_button=modal_button|safe %}
|
||||
{% if review_form_is_complete %}
|
||||
{% with modal_heading="You are about to submit a domain request for " domain_name_modal=requested_domain__name modal_description="Once you submit this request, you won’t be able to edit it until we review it. You’ll only be able to withdraw your request." modal_button_id="domain-request-form-submit-button" modal_button_text="Submit request" %}
|
||||
{% include 'includes/modal.html' %}
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
{% with modal_heading="Your request form is incomplete" modal_description='This request cannot be submitted yet. Return to the request and visit the steps that are marked as "incomplete."' modal_button_text="Return to request" cancel_button_only=True %}
|
||||
{% include 'includes/modal.html' %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<form method="post" id="submit-domain-request-form">
|
||||
{% csrf_token %}
|
||||
</form>
|
||||
|
||||
{% block after_form_content %}{% endblock %}
|
||||
|
||||
</main>
|
||||
|
|
|
@ -24,8 +24,26 @@
|
|||
<div class="usa-modal__footer">
|
||||
<ul class="usa-button-group">
|
||||
<li class="usa-button-group__item">
|
||||
{% if not_form and modal_button %}
|
||||
{{ modal_button }}
|
||||
{% if cancel_button_only %}
|
||||
<button
|
||||
type="button"
|
||||
class="usa-button"
|
||||
data-close-modal
|
||||
>
|
||||
{% if modal_button_text %}
|
||||
{{ modal_button_text }}
|
||||
{% else %}
|
||||
Cancel
|
||||
{% endif %}
|
||||
</button>
|
||||
{% elif modal_button_id and modal_button_text %}
|
||||
<button
|
||||
id="{{ modal_button_id }}"
|
||||
type="button"
|
||||
class="usa-button"
|
||||
>
|
||||
{{ modal_button_text }}
|
||||
</button>
|
||||
{% elif modal_button_url and modal_button_text %}
|
||||
<a
|
||||
href="{{ modal_button_url }}"
|
||||
|
@ -56,7 +74,7 @@
|
|||
Cancel
|
||||
</button>
|
||||
</form>
|
||||
{% elif not is_domain_request_form or review_form_is_complete %}
|
||||
{% elif not cancel_button_only %}
|
||||
<button
|
||||
type="button"
|
||||
class="usa-button usa-button--unstyled padding-105 text-center"
|
||||
|
|
|
@ -448,34 +448,21 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
|
|||
non_org_steps_complete = DomainRequest._form_complete(self.domain_request, self.request)
|
||||
org_steps_complete = len(self.db_check_for_unlocking_steps()) == len(self.steps)
|
||||
if (not self.is_portfolio and non_org_steps_complete) or (self.is_portfolio and org_steps_complete):
|
||||
modal_button = '<button type="submit" ' 'class="usa-button" ' ">Submit request</button>"
|
||||
context = {
|
||||
"not_form": False,
|
||||
"form_titles": self.titles,
|
||||
"steps": self.steps,
|
||||
"visited": self.storage.get("step_history", []),
|
||||
"is_federal": self.domain_request.is_federal(),
|
||||
"modal_button": modal_button,
|
||||
"modal_heading": "You are about to submit a domain request for ",
|
||||
"domain_name_modal": str(self.domain_request.requested_domain),
|
||||
"modal_description": "Once you submit this request, you won’t be able to edit it until we review it.\
|
||||
You’ll only be able to withdraw your request.",
|
||||
"review_form_is_complete": True,
|
||||
"user": self.request.user,
|
||||
"requested_domain__name": requested_domain_name,
|
||||
}
|
||||
else: # form is not complete
|
||||
modal_button = '<button type="button" class="usa-button" data-close-modal>Return to request</button>'
|
||||
context = {
|
||||
"not_form": True,
|
||||
"form_titles": self.titles,
|
||||
"steps": self.steps,
|
||||
"visited": self.storage.get("step_history", []),
|
||||
"is_federal": self.domain_request.is_federal(),
|
||||
"modal_button": modal_button,
|
||||
"modal_heading": "Your request form is incomplete",
|
||||
"modal_description": 'This request cannot be submitted yet.\
|
||||
Return to the request and visit the steps that are marked as "incomplete."',
|
||||
"review_form_is_complete": False,
|
||||
"user": self.request.user,
|
||||
"requested_domain__name": requested_domain_name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue