From d0beddc484e3bb055fdb4ea09c7c7acef046fafe Mon Sep 17 00:00:00 2001 From: Jerry Padgett Date: Tue, 25 Oct 2022 22:52:19 -0400 Subject: [PATCH] Missing form validation Questionnaires (#5868) * Missing form validation Questionnaires - add a dialog alert to show validation errors * - format form error message alert - prevent save form on save to registry --- .../questionnaire_assessments.php | 39 +++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/interface/forms/questionnaire_assessments/questionnaire_assessments.php b/interface/forms/questionnaire_assessments/questionnaire_assessments.php index 8d93a7bf2..8742545c8 100644 --- a/interface/forms/questionnaire_assessments/questionnaire_assessments.php +++ b/interface/forms/questionnaire_assessments/questionnaire_assessments.php @@ -142,18 +142,33 @@ try { if (!isPortal) { top.restoreSession(); } - let qr = LForms.Util.getFormFHIRData('QuestionnaireResponse', 'R4'); + if (formMode == 'register') { + return true; + } let formElement = document.getElementById("formContainer"); - let data = LForms.Util.getUserData(formElement, false, true, true); - document.getElementById('lform_response').value = JSON.stringify(data); - document.getElementById('questionnaire_response').value = JSON.stringify(qr); - if (!document.getElementById('questionnaire').value) { - let lForm = JSON.parse(document.getElementById('lform').value); - let qFhir = LForms.Util.getFormFHIRData("Questionnaire", 'R4', data); - document.getElementById('questionnaire').value = JSON.stringify(qFhir); + let notValid = LForms.Util.checkValidity(formElement); + if (notValid) { + notValid = "" + jsText(notValid) + ""; + let error = notValid.replace(/requires a value,/g, "requires a value,
"); + error = error.replace(/requires a value/g, "requires a value") + let formatText = "" + xl('Form failed validation!') + "
" + error; + dialog.alert(formatText).then(returned => { + dialog.close(); + return false; + }); + } else { + let qr = LForms.Util.getFormFHIRData('QuestionnaireResponse', 'R4'); + let data = LForms.Util.getUserData(formElement, false, true, true); + document.getElementById('lform_response').value = JSON.stringify(data); + document.getElementById('questionnaire_response').value = JSON.stringify(qr); + if (!document.getElementById('questionnaire').value) { + let lForm = JSON.parse(document.getElementById('lform').value); + let qFhir = LForms.Util.getFormFHIRData("Questionnaire", 'R4', data); + document.getElementById('questionnaire').value = JSON.stringify(qFhir); + } + return true; } - - return true; + return false; } function initUpdate() { @@ -382,7 +397,7 @@ try {
- +
@@ -399,7 +414,7 @@ try { - +