Skip to content

Commit

Permalink
bug/WP-113: Registration form entities bugs (#158)
Browse files Browse the repository at this point in the history
* Custom error message on entity id fields & now delete associated registration & entities/contacts on failure to write to db on entities/contacts

* Add upper threshold to NAIC & license codes and rework how at least one required entity ID is handled + custom error message for these fields

* Prevent writing any more entities/contacts to database if either fails

* Remove auto record deletion on writing contact/entity error

* Ensure deletion in one entity ID box does not raise custom error if another ID is complete
  • Loading branch information
edmondsgarrett committed Jun 12, 2023
1 parent 0142df5 commit 1cc0771
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form action="" method="POST">
<form id="registration-form" action="" method="POST">
{% csrf_token %}

{% if r %}
Expand Down Expand Up @@ -299,6 +299,8 @@ <h5 id="entity_header_{{ forloop.counter }}_{{r.reg_id}}">Entity {{ forloop.coun
class="integerfield"
id="license_number_{{forloop.counter}}_{{r.reg_id}}"
inputmode="numeric"
min="0"
max="2147483648"
{% if entity.license %} value="{{ entity.license }}" {% endif %}
/>

Expand All @@ -318,6 +320,8 @@ <h5 id="entity_header_{{ forloop.counter }}_{{r.reg_id}}">Entity {{ forloop.coun
class="integerfield"
id="naic_company_code_{{forloop.counter}}_{{r.reg_id}}"
inputmode="numeric"
min="0"
max="2147483648"
{% if entity.naic %} value="{{ entity.naic }}" {% endif %}
/>

Expand Down Expand Up @@ -460,16 +464,16 @@ <h4>
<div class="field-wrapper textinput required">
<div class="field-errors" style="display: none"></div>

<label for="entity_name">
<label for="entity_name_1">
Name<span class="asterisk">*</span>
</label>

<input
type="text"
name="entity_name"
name="entity_name_1"
required
class="textinput"
id="entity_name"
id="entity_name_1"
/>
</div>
<div class="field-wrapper required">
Expand All @@ -485,14 +489,14 @@ <h4>
<div class="field-wrapper textinput">
<div class="field-errors" style="display: none"></div>

<label for="fein"> FEIN<sup>5</sup> </label>
<label for="fein_1"> FEIN<sup>5</sup> </label>

<input
type="text"
name="fein"
name="fein_1"
placeholder="12-3456789"
class="textinput"
id="fein"
id="fein_1"
inputmode="numeric"
minlength="10"
maxlength="10"
Expand All @@ -507,15 +511,17 @@ <h4>
<div class="field-wrapper textinput">
<div class="field-errors" style="display: none"></div>

<label for="license_number"> License Number </label>
<label for="license_number_1"> License Number </label>

<input
type="number"
name="license_number"
name="license_number_1"
placeholder="1234567890"
class="integerfield"
id="license_number"
id="license_number_1"
inputmode="numeric"
min="0"
max="2147483648"
required
/>

Expand All @@ -526,15 +532,17 @@ <h4>
<div class="field-wrapper textinput">
<div class="field-errors" style="display: none"></div>

<label for="naic_company_code"> NAIC<sup>6</sup> Company Code </label>
<label for="naic_company_code_1"> NAIC<sup>6</sup> Company Code </label>

<input
type="number"
name="naic_company_code"
name="naic_company_code_1"
placeholder="12345"
class="integerfield"
id="naic_company_code"
id="naic_company_code_1"
inputmode="numeric"
min="0"
max="2147483648"
required
/>

Expand All @@ -558,50 +566,50 @@ <h6>File Submission</h6>

<ul id="types_of_files" class="checkboxselectmultiple">
<li>
<label for="types_of_files_eligibility_enrollment"
<label for="types_of_files_eligibility_enrollment_1"
><input
type="checkbox"
name="types_of_files_eligibility_enrollment"
name="types_of_files_eligibility_enrollment_1"
required
id="types_of_files_eligibility_enrollment"
id="types_of_files_eligibility_enrollment_1"
checked=""
disabled
/>Eligibility/Enrollment*</label
>
</li>
<li>
<label for="types_of_files_provider"
<label for="types_of_files_provider_1"
><input
type="checkbox"
name="types_of_files_provider"
id="types_of_files_provider"
name="types_of_files_provider_1"
id="types_of_files_provider_1"
/>Provider</label
>
</li>
<li>
<label for="types_of_files_medical"
<label for="types_of_files_medical_1"
><input
type="checkbox"
name="types_of_files_medical"
id="types_of_files_medical"
name="types_of_files_medical_1"
id="types_of_files_medical_1"
/>Medical</label
>
</li>
<li>
<label for="types_of_files_pharmacy"
<label for="types_of_files_pharmacy_1"
><input
type="checkbox"
name="types_of_files_pharmacy"
id="types_of_files_pharmacy"
name="types_of_files_pharmacy_1"
id="types_of_files_pharmacy_1"
/>Pharmacy</label
>
</li>
<li>
<label for="types_of_files_dental"
<label for="types_of_files_dental_1"
><input
type="checkbox"
name="types_of_files_dental"
id="types_of_files_dental"
name="types_of_files_dental_1"
id="types_of_files_dental_1"
/>Dental</label
>
</li>
Expand All @@ -619,16 +627,16 @@ <h6>
<div class="field-wrapper numberinput required">
<div class="field-errors" style="display: none"></div>

<label for="total_covered_lives">
<label for="total_covered_lives_1">
Total Covered Lives<span class="asterisk">*</span>
</label>

<input
type="number"
name="total_covered_lives"
name="total_covered_lives_1"
required
class="integerfield"
id="total_covered_lives"
id="total_covered_lives_1"
inputmode="numeric"
min="1"
step="1"
Expand All @@ -638,16 +646,16 @@ <h6>
<div class="field-wrapper numberinput required">
<div class="field-errors" style="display: none"></div>

<label for="claims_encounters_volume">
<label for="claims_encounters_volume_1">
Claims and Encounters Volume<span class="asterisk">*</span>
</label>

<input
type="number"
name="claims_encounters_volume"
name="claims_encounters_volume_1"
required
class="integerfield"
id="claims_encounters_volume"
id="claims_encounters_volume_1"
inputmode="numeric"
min="1"
/>
Expand All @@ -656,17 +664,17 @@ <h6>
<div class="field-wrapper numberinput required s-affixed-input-wrapper s-affixed-input-wrapper--prefix">
<div class="field-errors" style="display: none"></div>

<label for="total_claims_value">
<label for="total_claims_value_1">
Total Claims Value (USD<sup>7</sup>)<span class="asterisk">*</span>
</label>

<span class="s-affixed-input-wrapper__prefix">$</span>
<input
type="number"
name="total_claims_value"
name="total_claims_value_1"
required
class="integerfield"
id="total_claims_value"
id="total_claims_value_1"
inputmode="numeric"
step="0.01"
min="0.01"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
{% load static %}

<aside>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
{# To check for blank space only in text inputs #}
<script src="{% static 'utils/js/checkForBlankInputs.js' %}"></script>
{# Adds blank space listener to all text input fields on page load #}
<script>
const formTextInputs = document.querySelectorAll('input[type=text]');
noEmptyInputs(formTextInputs);
</script>
</script>
{# To require at least one "entity" identifier value #}
<script id="form-entity_id-required">
function entityIdGroupValidation(ent_no) {
const idGroup = Array.from(
document.querySelectorAll(`
input[name=fein_${ent_no}{% if r %}_{{r.reg_id}}{% endif %}],
input[name=license_number_${ent_no}{% if r %}_{{r.reg_id}}{% endif %}],
input[name=naic_company_code_${ent_no}{% if r %}_{{r.reg_id}}{% endif %}]`)
);
idGroup.forEach(i => i.addEventListener('invalid', function (event) {
if (event.target.validity.valueMissing) {
event.target.setCustomValidity('Please fill in at least one Number/Code.');
}
}));
idGroup.forEach(i => i.addEventListener('change', function (event) {
idGroup.forEach(j => {
j.required = true;
if (!event.target.validity.valueMissing || idGroup.some(input => input.value.length > 0)) { // if value exists, no other inputs in this group are required
j.setCustomValidity('');
j.required = false;
}
});
}));
}
</script>
{# To let user add and remove entities #}
{# RFE: Do not duplicate entity markup #}
{# IDEA: HTML template for any instance; used by markup for 0, JS for 1+ #}
Expand All @@ -32,7 +58,10 @@
{% else %}
1
{% endif %};


for (let ent_no = 1; ent_no < entities + 1; ent_no +=1) {
entityIdGroupValidation(ent_no); // add validation for entities already on form at page load
};
btnStatus();

addEntityBtn.addEventListener("click", () => {
Expand Down Expand Up @@ -92,6 +121,8 @@
class="integerfield"
id="license_number_${entities}{% if r %}_{{r.reg_id}}{% endif %}"
inputmode="numeric"
min="0"
max="2147483648"
required
/>
<div id="help-text-license_number_${entities}" class="help-text">
Expand All @@ -108,6 +139,8 @@
class="integerfield"
id="naic_company_code_${entities}{% if r %}_{{r.reg_id}}{% endif %}"
inputmode="numeric"
min="0"
max="2147483648"
required
/>
<div id="help-text-naic_company_code_${entities}" class="help-text">
Expand Down Expand Up @@ -246,11 +279,7 @@ <h6>
input[name=naic_company_code_${entities}{% if r %}_{{r.reg_id}}{% endif %}]
`)
);
const inputListener = e => {
inputs.filter(i => i !== e.target)
.forEach(i => (i.required = !e.target.value.length));
};
inputs.forEach(i => i.addEventListener('input', inputListener));
entityIdGroupValidation(entities); // add entity id validation for new entities on form

const addEntityNameInput = document.querySelectorAll(`input[name=entity_name_${entities}{% if r %}_{{r.reg_id}}{% endif %}]`);
noEmptyInputs(addEntityNameInput);
Expand Down Expand Up @@ -398,22 +427,4 @@ <h6>
btnStatus();
});
</script>
{# To require at least one "entity" identifier value #}
<script id="form-entity_id-required" type="module">
for (let ent_no = 1; ent_no < 6; ent_no++) {
const inputs = Array.from(
document.querySelectorAll(`
input[name=fein_${ent_no}{% if r %}_{{r.reg_id}}{% endif %}],
input[name=license_number_${ent_no}{% if r %}_{{r.reg_id}}{% endif %}],
input[name=naic_company_code_${ent_no}{% if r %}_{{r.reg_id}}{% endif %}]`)
);

const inputListener = e => {
inputs.filter(i => i !== e.target)
.forEach(i => (i.required = !e.target.value.length));
};

inputs.forEach(i => i.addEventListener('input', inputListener));
}
</script>
</aside>
Loading

0 comments on commit 1cc0771

Please sign in to comment.