Commit 9bc578fc by Owen Ryan Ang

Changed implementation for generating "others" field in options.

parent dd374a8a
...@@ -466,60 +466,67 @@ const inputChecklist = (key, validation) => { ...@@ -466,60 +466,67 @@ const inputChecklist = (key, validation) => {
var dropdownContent = document.createElement('div'); var dropdownContent = document.createElement('div');
dropdownContent.classList.add('dropdown-content'); dropdownContent.classList.add('dropdown-content');
dropdown1.appendChild(dropdownContent); dropdown1.appendChild(dropdownContent);
var isOther = false;
// Create the checkboxes for each item // Create the checkboxes for each item
items.forEach(function (item, index) { items.forEach(function (item, index) {
var div = document.createElement('div'); if (item.toLowerCase() === "other" || item.toLowerCase() === "others"){
div.classList.add('checkbox'); isOther = true;
}else{
var checkbox = document.createElement('input'); var div = document.createElement('div');
checkbox.type = 'checkbox'; div.classList.add('checkbox');
checkbox.name = 'checkboxChoices';
checkbox.value = item; var checkbox = document.createElement('input');
if (index == 0) checkbox.setAttribute('id', `${key}`); checkbox.type = 'checkbox';
checkbox.name = 'checkboxChoices';
div.appendChild(checkbox); checkbox.value = item;
var label = document.createTextNode(item); if (index == 0) checkbox.setAttribute('id', `${key}`);
div.appendChild(label);
dropdownContent.appendChild(div) div.appendChild(checkbox);
var label = document.createTextNode(item);
div.appendChild(label);
dropdownContent.appendChild(div)
}
}) })
// Create the checkbox dependent on an input text value
var dependentDiv = document.createElement('div');
dependentDiv.classList.add('checkbox');
var dependentCheckbox = document.createElement('input');
dependentCheckbox.type = 'checkbox';
dependentCheckbox.name = 'checkboxChoices';
dependentCheckbox.id = 'checkDP';
dependentCheckbox.value = ''; // Set the value here based on the input text
dependentDiv.appendChild(dependentCheckbox);
var dependentLabel = document.createTextNode('other');
dependentDiv.appendChild(dependentLabel);
dropdownContent.appendChild(dependentDiv);
// Initially hide the input text box if(isOther){
var inputTextBox = document.createElement('input'); // Create the checkbox dependent on an input text value
inputTextBox.type = 'text'; var dependentDiv = document.createElement('div');
inputTextBox.id = 'dependentTB'; dependentDiv.classList.add('checkbox');
inputTextBox.style.display = 'none'; var dependentCheckbox = document.createElement('input');
inputTextBox.style.padding = '0px'; dependentCheckbox.type = 'checkbox';
dropdownContent.appendChild(inputTextBox); dependentCheckbox.name = 'checkboxChoices';
dependentCheckbox.id = 'checkDP';
// Add event listener to the "other" checkbox dependentCheckbox.value = ''; // Set the value here based on the input text
dependentCheckbox.addEventListener('change', function () { dependentDiv.appendChild(dependentCheckbox);
if (dependentCheckbox.checked) {
inputTextBox.style.display = 'inline-block'; var dependentLabel = document.createTextNode('other');
} else { dependentDiv.appendChild(dependentLabel);
inputTextBox.style.display = 'none'; // Hide the input text box when "other" checkbox is unchecked dropdownContent.appendChild(dependentDiv);
}
// Update the value of the dependentCheckbox when the input value changes // Initially hide the input text box
dependentCheckbox.value = inputTextBox.value; var inputTextBox = document.createElement('input');
}); inputTextBox.type = 'text';
inputTextBox.id = 'dependentTB';
inputTextBox.style.display = 'none';
inputTextBox.style.padding = '0px';
dropdownContent.appendChild(inputTextBox);
// Add event listener to the "other" checkbox
dependentCheckbox.addEventListener('change', function () {
if (dependentCheckbox.checked) {
inputTextBox.style.display = 'inline-block';
} else {
inputTextBox.style.display = 'none'; // Hide the input text box when "other" checkbox is unchecked
}
// Update the value of the dependentCheckbox when the input value changes
dependentCheckbox.value = inputTextBox.value;
});
inputTextBox.addEventListener("input", event => { inputTextBox.addEventListener("input", event => {
dependentCheckbox.value = event.target.value; dependentCheckbox.value = event.target.value;
}); });
}
return dropdown1; return dropdown1;
} catch (err) { } catch (err) {
...@@ -546,58 +553,64 @@ const inputRadiolist = (key, validation) => { ...@@ -546,58 +553,64 @@ const inputRadiolist = (key, validation) => {
var dropdownContent = document.createElement('div'); var dropdownContent = document.createElement('div');
dropdownContent.classList.add('dropdown-content'); dropdownContent.classList.add('dropdown-content');
dropdown1.appendChild(dropdownContent); dropdown1.appendChild(dropdownContent);
var isOther = false;
// Create radio buttons for each item // Create radio buttons for each item
items.forEach((item, index) => { items.forEach((item, index) => {
var radioDiv = document.createElement('div'); if (item.toLowerCase() === "other" || item.toLowerCase() === "others"){
radioDiv.classList.add('radio-like-checkbox'); isOther = true;
}else{
var radio = document.createElement('input'); var radioDiv = document.createElement('div');
radio.type = 'radio'; radioDiv.classList.add('radio-like-checkbox');
radio.name = 'radioChoices';
radio.value = item; var radio = document.createElement('input');
if (index == 0) radio.setAttribute('id', `${key}`); radio.type = 'radio';
radio.name = 'radioChoices';
var label = document.createTextNode(item); radio.value = item;
radioDiv.appendChild(radio); if (index == 0) radio.setAttribute('id', `${key}`);
radioDiv.appendChild(label);
dropdownContent.appendChild(radioDiv); var label = document.createTextNode(item);
}); radioDiv.appendChild(radio);
radioDiv.appendChild(label);
// Create the radio button dependent on an input text value dropdownContent.appendChild(radioDiv);
var dependentDiv = document.createElement('div');
dependentDiv.classList.add('radio-like-checkbox');
var dependentRadio = document.createElement('input');
dependentRadio.type = 'radio';
dependentRadio.name = 'radioChoices';
dependentRadio.value = '';
dependentDiv.appendChild(dependentRadio);
var dependentLabel = document.createTextNode('other');
dependentDiv.appendChild(dependentLabel);
dropdownContent.appendChild(dependentDiv);
var inputTextBox = document.createElement('input');
inputTextBox.type = 'text';
inputTextBox.id = 'dependentTB';
inputTextBox.style.display = 'none';
inputTextBox.style.padding = '0px';
dropdownContent.appendChild(inputTextBox);
// Add event listener to the "other" radio button
dependentRadio.addEventListener('change', function () {
if (dependentRadio.checked) {
inputTextBox.style.display = 'inline-block';
} else {
inputTextBox.style.display = 'none'; // Hide the input text box when "other" radio button is unchecked
} }
}); });
if (isOther){
// Create the radio button dependent on an input text value
var dependentDiv = document.createElement('div');
dependentDiv.classList.add('radio-like-checkbox');
var dependentRadio = document.createElement('input');
dependentRadio.type = 'radio';
dependentRadio.name = 'radioChoices';
dependentRadio.value = '';
dependentDiv.appendChild(dependentRadio);
var dependentLabel = document.createTextNode('other');
dependentDiv.appendChild(dependentLabel);
dropdownContent.appendChild(dependentDiv);
var inputTextBox = document.createElement('input');
inputTextBox.type = 'text';
inputTextBox.id = 'dependentTB';
inputTextBox.style.display = 'none';
inputTextBox.style.padding = '0px';
dropdownContent.appendChild(inputTextBox);
// Add event listener to the "other" radio button
dependentRadio.addEventListener('change', function () {
if (dependentRadio.checked) {
inputTextBox.style.display = 'inline-block';
} else {
inputTextBox.style.display = 'none'; // Hide the input text box when "other" radio button is unchecked
}
});
inputTextBox.addEventListener("input", event => { inputTextBox.addEventListener("input", event => {
if (dependentRadio.checked) { if (dependentRadio.checked) {
dependentRadio.value = event.target.value; dependentRadio.value = event.target.value;
} }
}); });
}
return dropdown1; return dropdown1;
} catch (err) { } catch (err) {
...@@ -815,6 +828,7 @@ const deconstruct = async (section, container, classAttribute) => { ...@@ -815,6 +828,7 @@ const deconstruct = async (section, container, classAttribute) => {
case 'textarea': case 'textarea':
case 'alphanumeric': case 'alphanumeric':
case 'alphabet': case 'alphabet':
case 'email':
input = inputString(key, validation) input = inputString(key, validation)
break break
case 'specific': case 'specific':
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
"validation" : { "validation" : {
"fieldLength" : 20.0, "fieldLength" : 20.0,
"collection" : "radiolist", "collection" : "radiolist",
"items" : [ "Emergency Room", "Inpatient", "Outpatient" ], "items" : [ "Emergency Room", "Inpatient", "Outpatient", "others" ],
"mandatory" : true "mandatory" : true
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment