Passed
Push — master ( 2b7bb3...0db2dd )
by Clint A
06:52
created

total-selected-charges.js ➔ ???   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 14
rs 10
c 1
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A total-selected-charges.js ➔ ... ➔ ??? 0 3 1
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