@ministryofjustice/frontend 5.1.1 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/moj/all.bundle.js CHANGED
@@ -14,7 +14,7 @@
14
14
  *
15
15
  * {@link https://github.com/ministryofjustice/moj-frontend/releases}
16
16
  */
17
- const version = '5.1.1';
17
+ const version = '5.1.2';
18
18
 
19
19
  class AddAnother extends govukFrontend.Component {
20
20
  /**
@@ -90,7 +90,7 @@
90
90
  */
91
91
  updateAttributes($item, index) {
92
92
  $item.querySelectorAll('[data-name]').forEach($input => {
93
- if (!($input instanceof HTMLInputElement)) {
93
+ if (!this.isValidInputElement($input)) {
94
94
  return;
95
95
  }
96
96
  const name = $input.getAttribute('data-name') || '';
@@ -121,13 +121,23 @@
121
121
  */
122
122
  resetItem($item) {
123
123
  $item.querySelectorAll('[data-name], [data-id]').forEach($input => {
124
- if (!($input instanceof HTMLInputElement)) {
124
+ if (!this.isValidInputElement($input)) {
125
125
  return;
126
126
  }
127
- if ($input.type === 'checkbox' || $input.type === 'radio') {
128
- $input.checked = false;
129
- } else {
127
+ if ($input instanceof HTMLSelectElement) {
128
+ $input.selectedIndex = -1;
129
+ $input.value = '';
130
+ } else if ($input instanceof HTMLTextAreaElement) {
130
131
  $input.value = '';
132
+ } else {
133
+ switch ($input.type) {
134
+ case 'checkbox':
135
+ case 'radio':
136
+ $input.checked = false;
137
+ break;
138
+ default:
139
+ $input.value = '';
140
+ }
131
141
  }
132
142
  });
133
143
  }
@@ -157,6 +167,13 @@
157
167
  }
158
168
  }
159
169
 
170
+ /**
171
+ * @param {Element} $input - the input to validate
172
+ */
173
+ isValidInputElement($input) {
174
+ return $input instanceof HTMLInputElement || $input instanceof HTMLSelectElement || $input instanceof HTMLTextAreaElement;
175
+ }
176
+
160
177
  /**
161
178
  * Name for the component used when initialising using data-module attributes.
162
179
  */