saasufy-components 9.1.0 → 9.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/collection-adder-form.js +24 -32
- package/package.json +1 -1
- package/styles.css +1 -0
package/collection-adder-form.js
CHANGED
|
@@ -59,18 +59,12 @@ class CollectionAdderForm extends SocketConsumer {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// Clear any existing field errors
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// Clear error classes from all inputs
|
|
70
|
-
let allInputs = element.querySelectorAll('input, textarea, select');
|
|
71
|
-
allInputs.forEach(input => input.classList.remove('error'));
|
|
72
|
-
});
|
|
73
|
-
}
|
|
62
|
+
let existingFieldErrors = this.querySelectorAll('.collection-adder-field-error-container');
|
|
63
|
+
existingFieldErrors.forEach(el => el.remove());
|
|
64
|
+
|
|
65
|
+
// Clear error classes from all inputs
|
|
66
|
+
let allInputs = this.querySelectorAll('input, textarea, select');
|
|
67
|
+
allInputs.forEach(input => input.classList.remove('error'));
|
|
74
68
|
|
|
75
69
|
let trimSpaces = this.hasAttribute('trim-spaces');
|
|
76
70
|
|
|
@@ -184,26 +178,24 @@ class CollectionAdderForm extends SocketConsumer {
|
|
|
184
178
|
let input = inputElements.find(el => el.name === fieldName);
|
|
185
179
|
|
|
186
180
|
if (input) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
let
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
}
|
|
181
|
+
let inputType = input.type || (input.nodeName === 'TEXTAREA' ? 'textarea' : 'select');
|
|
182
|
+
|
|
183
|
+
// For radio buttons and checkboxes, just add error class to input(s)
|
|
184
|
+
if (inputType === 'radio') {
|
|
185
|
+
// Find all radio inputs with the same name
|
|
186
|
+
let radioInputs = inputElements.filter(el => el.name === fieldName && el.type === 'radio');
|
|
187
|
+
radioInputs.forEach(radio => radio.classList.add('error'));
|
|
188
|
+
} else if (inputType === 'checkbox') {
|
|
189
|
+
input.classList.add('error');
|
|
190
|
+
} else {
|
|
191
|
+
// For other input types, create and insert error message div before the input
|
|
192
|
+
let errorDiv = document.createElement('div');
|
|
193
|
+
errorDiv.classList.add('collection-adder-field-error-container');
|
|
194
|
+
errorDiv.classList.add('error');
|
|
195
|
+
let simpleFieldError = fieldError.replace(/^Invalid [^:]+:/i, '');
|
|
196
|
+
errorDiv.textContent = simpleFieldError;
|
|
197
|
+
|
|
198
|
+
input.parentNode.insertBefore(errorDiv, input);
|
|
207
199
|
}
|
|
208
200
|
}
|
|
209
201
|
}
|
package/package.json
CHANGED