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

Hai 750 #254

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
76 changes: 76 additions & 0 deletions configuration/pih/scripts/global/zl.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,80 @@ function updateLastCheckboxRequired(containerSelector) {

// Add the updateLastCheckboxRequired function to the beforeSubmit array to call it before form submission.
beforeSubmit.push(updateLastCheckbox);
}

usePatientAddressAsContactAddress();

function usePatientAddressAsContactAddress() {
jq(document).ready(function () {

// change the ckeckbox message based on the languade
var message = '';
var url = window.location.href;
var urlParams = new URLSearchParams(new URL(url).search);
var langParam = urlParams.get('lang');
message = langParam === 'fr' ? "Utilisez l'adresse du patient ?" : "Use the patient address ?"

//target the div containing the contact address
const divElement = jq('#contactQuestionLabel div');

//creating a check, to be checked if clinician wants to use patient address as contact one
const checkboxElement = jq("<input>", {
type: "checkbox",
id: "question_address",
name: "question_address"
});

//Creating a label to show the checkbox title
const labelElement = jq("<label>", {
for: "question_address",
text: message
});

//creating a break line to push other elements a litle bit down
const brElement = $("<br>");
divElement.prepend(checkboxElement, labelElement, brElement);

// checkbox event occurs here
jq('#question_address').on('change', function () {
if (this.checked) {
// get and set the new address detail from patient to contact
getPatienAddressInfo();

} else {
clearInputValue();
}
});
});

}

function getPatienAddressInfo() {

//creating an array to store patient adress
var valuesArray = [];
var manualEntryAddress;
jq("#personAddressQuestion div input[type='text']").each(function () {
valuesArray.push(jq(this).val());

});

console.table(valuesArray)
manualEntryAddress = $("#personAddressQuestion div input[type='text']:last").val()
jq("#contactQuestionLabel div input[type='text']:last").val(manualEntryAddress);

// target the contact address input and set the new value
jq("#contactQuestionLabel input[type='text']").each(function (index) {
if (index < valuesArray.length) {
jq(this).val(valuesArray[index]);
Copy link
Member

@mogoodrich mogoodrich Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a line: " jq(this).data('legalValues', [ valuesArray[index] ])" which I think needs to happen for the entry to be considered "valid" (see my overall comments).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added focused class to the autocomplete when the checkbox is checked. I hoped that would help. it stil does not save in DB

jq(this).data('legalValues', [valuesArray[index]])
}
});
}

function clearInputValue() {
jq("#contactQuestionLabel div input[type='text']").each(function () {
jq(this).val('');
});

}