Total Complexity | 7 |
Complexity/F | 1.75 |
Lines of Code | 40 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import forEach from 'lodash.foreach' |
||
2 | import currency from 'currency.js' |
||
3 | |||
4 | function selectedTotal() { |
||
5 | let total = 0.0 |
||
6 | |||
7 | forEach( |
||
8 | document.getElementsByClassName('charges__item-checkbox-input'), |
||
9 | element => { |
||
10 | if (element.checked) { |
||
11 | total += Number.parseFloat(element.dataset.feeBalance) |
||
12 | } |
||
13 | } |
||
14 | ) |
||
15 | |||
16 | document.getElementById('totalSelectedAmount').innerHTML = `$${currency( |
||
17 | total |
||
18 | )}` |
||
19 | |||
20 | if (total > 0) { |
||
21 | document.getElementById('submitButton').removeAttribute('disabled') |
||
22 | } else { |
||
23 | document.getElementById('submitButton').setAttribute('disabled', 'disabled') |
||
24 | } |
||
25 | } |
||
26 | |||
27 | document.addEventListener('DOMContentLoaded', () => { |
||
28 | if (!document.getElementsByClassName('charges__item-checkbox-input').length) { |
||
29 | return |
||
30 | } |
||
31 | |||
32 | selectedTotal() |
||
33 | |||
34 | forEach( |
||
35 | document.getElementsByClassName('charges__item-checkbox-input'), |
||
36 | element => { |
||
37 | element.addEventListener('click', selectedTotal) |
||
38 | } |
||
39 | ) |
||
40 | }) |
||
41 |