Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation function changes #139

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions configuration/pih/htmlforms/hiv/section-hiv-history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
setUpNextButtonForSections('hiv-history');
setUpExpandableContacts('<uimessage code="pihcore.invalid.phoneNumber"/>');
setUpExpandableTransferAndReferralDetails();
setUpDatepickerStartAndEndDateValidation('<uimessage code="pihcore.date.error.inTheFuture"/>','<uimessage code="pihcore.startDate.greater"/>');
});
</script>
</ifMode>
Expand Down Expand Up @@ -1406,16 +1407,16 @@
<repeat>
<template>
<obsgroup groupingConceptId="PIH:1501">
<tr>
<tr class="startDateEndDate">
<td>
<obs conceptId="CIEL:1282" answerConceptId="{conceptH}"
answerLabel="{drugname}"
toggle="{id: '{drugname}-hx', style: 'dim'}" />
</td>
<td class="{drugname}-hx">
<obs conceptId="CIEL:1190"/>
<td class="{drugname}-hx startDate">
<obs conceptId="CIEL:1190" />
</td>
<td class="{drugname}-hx">
<td class="{drugname}-hx endDate">
<obs conceptId="CIEL:1191" />
</td>
</tr>
Expand All @@ -1427,7 +1428,7 @@
<repeat>
<template>
<obsgroup groupingConceptId="PIH:1501">
<tr>
<tr class="startDateEndDate">
<td>
<obs conceptId="CIEL:1282" answerConceptId="{conceptH}"
answerLabel="{drugname}"
Expand All @@ -1437,10 +1438,10 @@
answerConceptIds="CIEL:159943, CIEL:159944" />
</p>
</td>
<td class="{drugname}-hx">
<td class="{drugname}-hx startDate">
<obs conceptId="CIEL:1190"/>
</td>
<td class="{drugname}-hx">
<td class="{drugname}-hx endDate">
<obs conceptId="CIEL:1191" />
</td>
</tr>
Expand All @@ -1452,16 +1453,16 @@
<repeat>
<template>
<obsgroup groupingConceptId="PIH:1501">
<tr>
<tr class="startDateEndDate">
<td>
<obs conceptId="CIEL:1282" answerConceptId="{conceptH}"
answerLabel="{drugname}"
toggle="{id: '{drugname}-hx', style: 'dim'}" />
</td>
<td class="{drugname}-hx">
<td class="{drugname}-hx startDate">
<obs conceptId="CIEL:1190"/>
</td>
<td class="{drugname}-hx">
<td class="{drugname}-hx endDate">
<obs conceptId="CIEL:1191" />
</td>
</tr>
Expand Down Expand Up @@ -1497,15 +1498,15 @@
<repeat>
<template>
<obsgroup groupingConceptId="PIH:1590">
<tr>
<tr class="startDateEndDate">
<td>
<obs conceptId="CIEL:1282" answerConceptId="{concept}"
toggle="{id: '{hivMedHx}', style: 'dim'}" />
</td>
<td class="{hivMedHx}">
<td class="{hivMedHx} startDate">
<obs conceptId="CIEL:1190"/>
</td>
<td class="{hivMedHx}">
<td class="{hivMedHx} endDate">
<obs conceptId="CIEL:1191" allowFutureDates="true"/>
</td>
</tr>
Expand All @@ -1519,15 +1520,15 @@

<!-- Other HIV regimen -->
<obsgroup groupingConceptId="PIH:1590">
<tr>
<tr class="startDateEndDate">
<td>
<obs conceptId="CIEL:1282" answerConceptId="CIEL:5622"
toggle="{id: 'otherHivMedHx', style: 'dim'}" />
</td>
<td class="otherHivMedHx">
<td class="otherHivMedHx startDate">
<obs conceptId="CIEL:1190"/>
</td>
<td class="otherHivMedHx">
<td class="otherHivMedHx endDate">
<obs conceptId="CIEL:1191" allowFutureDates="true"/>
</td>
</tr>
Expand Down Expand Up @@ -1572,18 +1573,18 @@
<repeat>
<template>
<obsgroup groupingConceptId="PIH:Family planning history construct">
<tr>
<tr class="startDateEndDate">
<td id="{comment}-fp">
<obs conceptId="CIEL:374"
answerConceptId="{fpMethod}"
style="checkbox"
toggle="{id: '{comment}-date', style: 'dim'}"
/>
</td>
<td class="{comment}-date">
<td class="{comment}-date startDate">
<obs conceptId="CIEL:163757"/>
</td>
<td class="{comment}-date">
<td class="{comment}-date endDate">
<obs conceptId="CIEL:163758" allowFutureDates="true"/>
</td>
</tr>
Expand All @@ -1600,18 +1601,18 @@

<!-- Other family planning -->
<obsgroup groupingConceptId="PIH:Family planning history construct">
<tr>
<tr class="startDateEndDate">
<td>
<obs conceptId="CIEL:374"
answerConceptId="CIEL:5622"
style="checkbox"
toggle="{id: 'other-fp', style: 'dim'}"
/>
</td>
<td class="other-fp">
<td class="other-fp startDate">
<obs conceptId="CIEL:163757"/>
</td>
<td class="other-fp">
<td class="other-fp endDate">
<obs conceptId="CIEL:163758" allowFutureDates="true"/>
</td>
</tr>
Expand Down
82 changes: 28 additions & 54 deletions configuration/pih/scripts/global/zl.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,66 +88,40 @@ function setUpExpandableContacts(badPhoneNumberMsg) {

}

function setUpDatepickerStartAndEndDateValidation(badDateInTheFutureMsg,badStartDateGreaterThanEndDateMsg){
function setUpDatepickerStartAndEndDateValidation(badDateInTheFutureMsg, badStartDateGreaterThanEndDateMsg){

// Any time the hidden value input of a date picker wrapped in specific classes is changed, validate dates
jq(".startDateEndDate").each(function(j, domEl){
setUpDatepickers(this);
let startDateSection = jq(this).find('.startDate');
let endDateSection = jq(this).find('.endDate');
jq(startDateSection).find('input[type=hidden]').change(function(e) {
validateStartAndEndDates(startDateSection, endDateSection);
});
jq(endDateSection).find('input[type=hidden]').change(function(e) {
validateStartAndEndDates(startDateSection, endDateSection);
});
});

function setUpDatepickers(containerNode) {
const startDatepicker = jq(jq(containerNode).find('.startDate'));
const endDatepicker = jq(jq(containerNode).find('.endDate'));

startDatepicker.change(function (e) {
let startDate = Date.parse(e.target.value);
let endDate = Date.parse(endDatepicker.find('input[type=text]').val());

if (startDate > Date.now()) {
jq(this).find('span').show();
jq(this).find('span').text(badDateInTheFutureMsg);
setButtonsDisabled(true)
} else {
jq(this).find('span').hide();
jq(this).find('span').text('');
setButtonsDisabled(false)
}

if (endDate > Date.now()) {
endDatepicker.find('span').show();
endDatepicker.find('span').text(badDateInTheFutureMsg);
setButtonsDisabled(true)
}
if (startDate > endDate) {
endDatepicker.find('span').show();
endDatepicker.find('span').text(badStartDateGreaterThanEndDateMsg);
setButtonsDisabled(true)
}
if (startDate < endDate && endDate < Date.now()) {
endDatepicker.find('span').hide();
endDatepicker.find('span').text('');
setButtonsDisabled(false)
}
});
function validateStartAndEndDates(startDateSection, endDateSection) {
let startDate = Date.parse(jq(startDateSection).find('input[type=hidden]').val());
let endDate = Date.parse(jq(endDateSection).find('input[type=hidden]').val());
let sdErrorDiv = jq(startDateSection).find('.field-error');
let edErrorDiv = jq(endDateSection).find('.field-error');

endDatepicker.change(function (e) {
let endDate = Date.parse(e.target.value);
let startDate = Date.parse(startDatepicker.find('input[type=text]').val());
// We are re-validating, so remove any previous errors
jq(sdErrorDiv).hide().text('');
jq(edErrorDiv).hide().text('');

if (endDate > Date.now()) {
jq(this).find('span').show();
jq(this).find('span').text(badDateInTheFutureMsg);
setButtonsDisabled(true)
}
if (startDate > endDate) {
jq(this).find('span').show();
jq(this).find('span').text(badStartDateGreaterThanEndDateMsg);
setButtonsDisabled(true)
}
if (startDate < endDate && endDate < Date.now()){
jq(this).find('span').hide();
jq(this).find('span').text('');
setButtonsDisabled(false)
}
// Show errors as appropriate for either start date, end date, or both
if (startDate > endDate) {
jq(sdErrorDiv).show().text(badStartDateGreaterThanEndDateMsg);
jq(edErrorDiv).show().text(badStartDateGreaterThanEndDateMsg);
}

// At the end, disable or enable submission buttons based on whether there are any visible errors
setButtonsDisabled(false);
jq('.field-error:visible').each(function(index) {
setButtonsDisabled(true);
});
}

Expand Down