Total Complexity | 7 |
Complexity/F | 0 |
Lines of Code | 45 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | const getDeptInput = (): HTMLSelectElement | null => |
||
2 | document.querySelector("select#department"); |
||
3 | const getGovEmailWrapper = () => document.querySelector("#gov_email_wrapper"); |
||
4 | const getGovEmailInput = (): HTMLInputElement | null => |
||
5 | document.querySelector("input#gov_email"); |
||
6 | |||
7 | const hideGovEmail = (): void => { |
||
8 | const wrapper = getGovEmailWrapper(); |
||
9 | if (wrapper !== null) { |
||
10 | wrapper.setAttribute("data-c-visibility", "hidden"); |
||
11 | } |
||
12 | const input = getGovEmailInput(); |
||
13 | if (input !== null) { |
||
14 | input.removeAttribute("required"); |
||
15 | } |
||
16 | }; |
||
17 | |||
18 | const showGovEmail = (): void => { |
||
19 | const wrapper = getGovEmailWrapper(); |
||
20 | if (wrapper !== null) { |
||
21 | wrapper.removeAttribute("data-c-visibility"); |
||
22 | } |
||
23 | const input = getGovEmailInput(); |
||
24 | if (input !== null) { |
||
25 | input.setAttribute("required", ""); |
||
26 | } |
||
27 | }; |
||
28 | |||
29 | const handleDeptChange = (event: Event): void => { |
||
30 | if (event.target instanceof HTMLSelectElement) { |
||
31 | const { value } = event.target; |
||
32 | const NOT_IN_GOV = "0"; |
||
33 | if (value !== null && value !== "" && value !== NOT_IN_GOV) { |
||
34 | showGovEmail(); |
||
35 | } else { |
||
36 | hideGovEmail(); |
||
37 | } |
||
38 | } |
||
39 | }; |
||
40 | |||
41 | const deptInput = getDeptInput(); |
||
42 | if (deptInput !== null) { |
||
43 | deptInput.addEventListener("change", handleDeptChange); |
||
44 | } |
||
45 |