tangy-form
Advanced tools
Comparing version 4.45.4 to 4.46.0
# CHANGELOG | ||
## v4.46.0 | ||
Section Scoring Updates: | ||
- Add `<section_id>_percet` and `<section_id>_denominator` to the form item outputs. | ||
- Prevent scoring of both tangy-timed, custom-scoring and regular scoring in the same section. | ||
Rules: | ||
- custom scoring always returns a percent | ||
- users should only use one type of input per scoring section | ||
- if there is a tangy-timed input, the score is the average of the percents of each grid. All other scores are ignored. | ||
## v4.45.4 | ||
@@ -4,0 +15,0 @@ |
{ | ||
"name": "tangy-form", | ||
"description": "A form element for lazy loaded multipage forms", | ||
"version": "4.45.4", | ||
"version": "4.46.0", | ||
"main": "tangy-form.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -775,34 +775,55 @@ import { PolymerElement, html } from '@polymer/polymer/polymer-element.js'; | ||
.forEach(input => inputs.push(input.getModProps && window.useShrinker ? input.getModProps() : input.getProps())) | ||
let score = 0 | ||
let percent = 0 | ||
let denominator = 0 | ||
let tangyTimedPercents = []; | ||
this.inputs = inputs | ||
if (this.querySelector('[name]')) { | ||
const tangyFormItem = this.querySelector('[name]').parentElement | ||
if(tangyFormItem.hasAttribute('scoring-section')) { | ||
const selections = tangyFormItem.getAttribute('scoring-fields') || [] | ||
if(selections.length>0){ | ||
const selectionsArray = selections.split(',') | ||
function findObjectByKey(array, key, value) { | ||
for (let i = 0; i < array.length; i++) { if (array[i] == key) {return array[i];} | ||
} return null; | ||
} | ||
this.inputs.forEach(input => { | ||
const a = findObjectByKey(selectionsArray, input.name) | ||
if (a != null){ | ||
let value; | ||
if (input.tagName === 'TANGY-TIMED') { | ||
//each grid present is scored as "number of correct items"/"number of total items" *100 | ||
const correct = numberOfCorrectItems(input); | ||
const total = input.value.length | ||
value = Math.round((correct/total) * 100).toString(); | ||
/* | ||
* Per the documentation: | ||
* - custom scoring always returns a percent | ||
* - users are supposed to only have one type of input per scoring section | ||
* - if there is a tangy-timed input, the score is the average of the percents of each grid. All other scores are ignored. | ||
*/ | ||
if (tangyFormItem.hasAttribute('custom-scoring-logic') && tangyFormItem.getAttribute('custom-scoring-logic').trim().length > 0) { | ||
score = this.customScore | ||
percent = score | ||
denominator = 100 | ||
} else { | ||
const selections = tangyFormItem.getAttribute('scoring-fields') || [] | ||
if (selections.length > 0) { | ||
const selectionsArray = selections.split(',') | ||
function findObjectByKey(array, key, value) { | ||
for (let i = 0; i < array.length; i++) { if (array[i] == key) {return array[i];} | ||
} return null; | ||
} | ||
this.inputs.forEach(input => { | ||
const a = findObjectByKey(selectionsArray, input.name) | ||
if (a != null) { | ||
let value; | ||
if (input.tagName === 'TANGY-TIMED') { | ||
//each grid present is scored as "number of correct items"/"number of total items" *100 aka a percent | ||
const correct = numberOfCorrectItems(input); | ||
const total = input.value.length | ||
value = Math.round((correct/total) * 100).toString(); | ||
tangyTimedPercents.push(value); | ||
} else { | ||
value = getValue(input.name); | ||
score += sumScore(value) | ||
denominator += 1 | ||
} | ||
} | ||
}) | ||
if (tangyTimedPercents.length > 0) { | ||
percent = Math.round(tangyTimedPercents.reduce((a, b) => parseInt(a) + parseInt(b)) / tangyTimedPercents.length) | ||
score = percent | ||
denominator = 100 | ||
} else { | ||
value = getValue(input.name); | ||
percent = Math.round((score/denominator) * 100) | ||
} | ||
score += sumScore(value)} | ||
}) | ||
} | ||
} | ||
if(tangyFormItem.hasAttribute('custom-scoring-logic')&&tangyFormItem.getAttribute('custom-scoring-logic').trim().length>0){ | ||
score = this.customScore | ||
} | ||
function sumScore(value) { | ||
@@ -822,2 +843,12 @@ let s = 0 | ||
this.inputs = [...inputs, scoreEl.getModProps && window.useShrinker ? scoreEl.getModProps() : scoreEl.getProps()] | ||
const countEl = document.createElement('tangy-input') | ||
countEl.name = `${tangyFormItem.getAttribute('id')}_score_denominator` | ||
countEl.value = denominator | ||
this.inputs = [...this.inputs, countEl.getModProps && window.useShrinker ? countEl.getModProps() : countEl.getProps()] | ||
const percentEl = document.createElement('tangy-input') | ||
percentEl.name = `${tangyFormItem.getAttribute('id')}_score_percent` | ||
percentEl.value = percent | ||
this.inputs = [...this.inputs, percentEl.getModProps && window.useShrinker ? percentEl.getModProps() : percentEl.getProps()] | ||
} | ||
@@ -824,0 +855,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
5313410
24615