Commit ee75285
committed
Refactor search form JS
Why these changes are being introduced:
During usability testing, stakeholders noted that the form can
enter a state in which they keyword field is incorrectly required.
(E.g., the geodistance panel is open, but the keyword input still
has the `required` attribute.)
In our attempts to replicate this bug, we have intermittently gotten
the form into a similar out-of-sync state. However, we have not
been able to replicate it consistently. Part of the problem is
the poor structure of the search form JS, which makes the script
difficult to debug.
Relevant ticket(s):
* [GDT-302](https://mitlibraries.atlassian.net/browse/GDT-302)
* [TIMX-281](https://mitlibraries.atlassian.net/browse/TIMX-281)
How this addresses that need:
This refactors the search form JS to be more well structured,
concise, and DRY, with the intention of resolving two tickets:
* GDT-302, the bug mentioned above. To resolve this, we delay the
execution of the functions that trigger the keyword input state
change, so as to avoid the syncing issues we found in testing.
* TIMX-281, a bug in non-GDT form state that prevents the visual
changes to icon and placeholder when the advanced search panel
is open.
Because we can't consistently replicate the bug that GDT-302
seeks to address, I can't say with certainty that this fixes the
problem. I've tried click-testing it, and certain behavior that
had previously gotten it out of sync no longer does. At minimum,
the refactor should improve the maintainability of our codebase
and make it easier to debug any future issues that may emerge.
Side effects of this change:
`var` is intentionally used instead of `const` or `let`. When
form submission fails with a redirect, Rails seems not to trigger
a full page reload. This causes the JS interpreter to throw an
error for modifying variables that have already been declare, unless
we declare them with `var`.
Since `var` is still valid JS, albeit not ideal, it's preferable
at this point to overriding Rails (likely Turbo) behavior on
form submit.1 parent 03f29ec commit ee75285
File tree
3 files changed
+92
-127
lines changed- app
- assets/stylesheets/partials
- javascript
- views/search
3 files changed
+92
-127
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | 51 | | |
60 | 52 | | |
61 | 53 | | |
| |||
71 | 63 | | |
72 | 64 | | |
73 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
74 | 82 | | |
75 | 83 | | |
76 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
13 | 6 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
20 | 11 | | |
21 | | - | |
22 | | - | |
23 | 12 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
38 | 17 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
53 | 21 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 22 | + | |
| 23 | + | |
62 | 24 | | |
63 | 25 | | |
64 | 26 | | |
65 | 27 | | |
66 | | - | |
67 | | - | |
| 28 | + | |
68 | 29 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
102 | 35 | | |
103 | | - | |
| 36 | + | |
104 | 37 | | |
105 | | - | |
| 38 | + | |
106 | 39 | | |
107 | | - | |
108 | | - | |
109 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
110 | 45 | | |
111 | | - | |
| 46 | + | |
| 47 | + | |
112 | 48 | | |
113 | | - | |
| 49 | + | |
114 | 50 | | |
115 | | - | |
116 | | - | |
117 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
118 | 55 | | |
119 | | - | |
| 56 | + | |
120 | 57 | | |
121 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
122 | 79 | | |
123 | 80 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | | - | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
12 | | - | |
13 | 10 | | |
14 | | - | |
15 | 11 | | |
16 | 12 | | |
17 | 13 | | |
18 | 14 | | |
19 | 15 | | |
20 | | - | |
21 | 16 | | |
22 | | - | |
23 | 17 | | |
24 | 18 | | |
25 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
26 | 23 | | |
27 | 24 | | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
31 | 28 | | |
32 | | - | |
| 29 | + | |
33 | 30 | | |
34 | 31 | | |
35 | 32 | | |
36 | 33 | | |
37 | | - | |
| 34 | + | |
38 | 35 | | |
39 | | - | |
| 36 | + | |
40 | 37 | | |
41 | | - | |
| 38 | + | |
| 39 | + | |
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
| |||
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
97 | | - | |
| 95 | + | |
98 | 96 | | |
99 | | - | |
| 97 | + | |
100 | 98 | | |
101 | | - | |
| 99 | + | |
| 100 | + | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
| |||
145 | 144 | | |
146 | 145 | | |
147 | 146 | | |
148 | | - | |
| 147 | + | |
149 | 148 | | |
150 | | - | |
| 149 | + | |
151 | 150 | | |
152 | | - | |
| 151 | + | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
0 commit comments