Total Complexity | 5 |
Complexity/F | 1.67 |
Lines of Code | 36 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | 'use strict'; |
||
2 | |||
3 | $(document).ready(function () { |
||
4 | |||
5 | let $checkbox = $('#page_add_contact_form'); |
||
6 | let $emailContainer = $('#email-address'); |
||
7 | let $emailField = $('#page_contact_email_address'); |
||
8 | |||
9 | |||
10 | if ($checkbox.attr("checked") === 'checked') { |
||
11 | $emailContainer.slideDown(); |
||
12 | $emailField.prop('required', true); |
||
13 | } |
||
14 | |||
15 | // Event Handler |
||
16 | $checkbox.on('change', function () { |
||
17 | |||
18 | updateDisplay(); |
||
19 | }); |
||
20 | |||
21 | // Action |
||
22 | |||
23 | function updateDisplay() { |
||
24 | |||
25 | let isChecked = $checkbox.is(':checked'); |
||
26 | |||
27 | if (isChecked) { |
||
28 | $emailContainer.slideDown(); |
||
29 | $emailField.focus().prop('required', true); |
||
30 | } else { |
||
31 | $emailContainer.slideUp(); |
||
32 | $emailField.prop('required', false); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | }); |
||
37 |