Skip to content

Commit

Permalink
TASK 3284, 3615: Change true/false to yes/no, fix conditional hide/sh…
Browse files Browse the repository at this point in the history
…ow for dropdowns
  • Loading branch information
mihailistov committed Mar 26, 2024
1 parent 089021b commit 9fffd81
Show file tree
Hide file tree
Showing 9 changed files with 502 additions and 17 deletions.
2 changes: 1 addition & 1 deletion assets/application/js/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function () {
const src =
'https://cdn.jsdelivr.net/gh/bcgov/nr-af-pods@dev/powerpod/releases/powerpod-0.9.4.min.js';
'https://cdn.jsdelivr.net/gh/bcgov/nr-af-pods@dev/powerpod/releases/powerpod-0.9.5.min.js';
const script = document.createElement('script');
script.setAttribute('async', '');
script.src = src;
Expand Down
2 changes: 1 addition & 1 deletion assets/claim/js/claim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function () {
const src =
'https://cdn.jsdelivr.net/gh/bcgov/nr-af-pods@dev/powerpod/releases/powerpod-0.9.4.min.js';
'https://cdn.jsdelivr.net/gh/bcgov/nr-af-pods@dev/powerpod/releases/powerpod-0.9.5.min.js';
const script = document.createElement('script');
script.setAttribute('async', '');
script.src = src;
Expand Down
2 changes: 1 addition & 1 deletion powerpod/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "powerpod",
"type": "module",
"version": "0.9.4",
"version": "0.9.5",
"description": "Powerpod is a jQuery plugin that enhances functionality of Power Pages components.",
"main": "dist/powerpod",
"scripts": {
Expand Down
479 changes: 479 additions & 0 deletions powerpod/releases/powerpod-0.9.5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion powerpod/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import typescript from '@rollup/plugin-typescript';
import css from 'rollup-plugin-import-css';

const licenseContent = `/*!
* powerpod 0.9.4
* powerpod 0.9.5
* https://github.com/bcgov/nr-af-pods/powerpod
*
* @license GPLv3 for open source use only
Expand Down
2 changes: 1 addition & 1 deletion powerpod/src/js/common/fieldConditionalLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function setupDependentRequiredField({
}
// @ts-ignore
const tr = dependentOnElement.closest('tr');
const input = getControlValue(tr);
const input = getControlValue({ tr, rawValue: true });
logger.info({
fn: setupDependentRequiredField,
message: `Setting up dependent field dependentOnElementTag: ${dependentOnElementTag} with value: ${input}`,
Expand Down
4 changes: 2 additions & 2 deletions powerpod/src/js/common/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ export function generateFormJson() {
logger.info({
fn: generateFormJson,
message: `For controlType: ${controlType}; found questionText: ${questionText}, try finding answerText next...`,
data: { tr }
data: { tr },
});

const answerText = getControlValue(tr);
const answerText = getControlValue({ tr });

logger.info({
fn: generateFormJson,
Expand Down
24 changes: 15 additions & 9 deletions powerpod/src/js/common/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,39 @@ export function getInfoValue(tr) {
return questionText;
}

export function getControlValue(tr) {
export function getControlValue({ tr, rawValue = false }) {
const type = getControlType(tr);

logger.info({
fn: getControlValue,
message: `Attempting to get control value for type: ${type}`,
message: `Attempting to get control value for type: ${type}, rawValue: ${rawValue}`,
});

const answerDiv = tr.querySelector('.control');
const controlDiv = tr.querySelector('.control');

if (type === HtmlElementType.CurrencyInput) {
return `$${answerDiv?.querySelector('input')?.value}`;
const value = controlDiv?.querySelector('input')?.value;
if (rawValue) return value;
return `$${value}`;
} else if (type === HtmlElementType.Input) {
return answerDiv?.querySelector('input')?.value;
return controlDiv?.querySelector('input')?.value;
} else if (type === HtmlElementType.DatePicker) {
return answerDiv?.querySelector('div > .datetimepicker > input')?.value;
return controlDiv?.querySelector('div > .datetimepicker > input')?.value;
} else if (type === HtmlElementType.TextArea) {
return answerDiv?.querySelector('textarea').value?.replace(/\n/g, ' ');
return controlDiv?.querySelector('textarea').value?.replace(/\n/g, ' ');
} else if (type === HtmlElementType.DropdownSelect) {
const selectElement = answerDiv?.querySelector('select');
const selectElement = controlDiv?.querySelector('select');
if (rawValue) return selectElement.value;
const selectedIndex = selectElement?.selectedIndex;
const selectedOption = selectElement.options[selectedIndex];
const selectedOptionText =
selectedOption.textContent || selectedOption.innerText;
return selectedOptionText;
} else if (type === HtmlElementType.Checkbox) {
return answerDiv?.querySelector('input')?.checked;
const checked = controlDiv?.querySelector('input')?.checked;
if (rawValue) return checked;
if (checked) return 'Yes';
return 'No';
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion powerpod/src/js/powerpod.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function setAPI() {
};
};
// @ts-ignore
POWERPOD.version = '0.9.4';
POWERPOD.version = '0.9.5';
// @ts-ignore
win.powerpod = POWERPOD;
}

0 comments on commit 9fffd81

Please sign in to comment.