saasufy-components 3.5.0 → 3.6.0
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/model-input.js +19 -4
- package/package.json +1 -1
- package/styles.css +2 -2
package/model-input.js
CHANGED
|
@@ -167,10 +167,11 @@ class ModelInput extends SocketConsumer {
|
|
|
167
167
|
elementType = 'input';
|
|
168
168
|
}
|
|
169
169
|
this.inputElement = document.createElement(elementType);
|
|
170
|
+
let optionList = null;
|
|
170
171
|
if (type === 'select') {
|
|
171
172
|
if (options) {
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
optionList = options.split(',');
|
|
174
|
+
let optionElements = optionList
|
|
174
175
|
.map((option) => {
|
|
175
176
|
return `<option value="${option}">${option}</option>`;
|
|
176
177
|
})
|
|
@@ -208,7 +209,7 @@ class ModelInput extends SocketConsumer {
|
|
|
208
209
|
this.appendChild(errorMessageContainer);
|
|
209
210
|
}
|
|
210
211
|
this.appendChild(this.inputElement);
|
|
211
|
-
let destroyInputSync = this.syncInputElementWithModel(this.inputElement, model, modelField, errorMessageContainer);
|
|
212
|
+
let destroyInputSync = this.syncInputElementWithModel(this.inputElement, model, modelField, errorMessageContainer, optionList);
|
|
212
213
|
this.destroy = () => {
|
|
213
214
|
destroyInputSync();
|
|
214
215
|
this.isLoadedConsumer && this.isLoadedConsumer.kill();
|
|
@@ -233,9 +234,22 @@ class ModelInput extends SocketConsumer {
|
|
|
233
234
|
}
|
|
234
235
|
}
|
|
235
236
|
|
|
236
|
-
|
|
237
|
+
verifyValue(fieldValue, optionList, inputElement, messageContainerElement) {
|
|
238
|
+
if (optionList && !optionList.includes(fieldValue)) {
|
|
239
|
+
inputElement.classList.add('error');
|
|
240
|
+
inputElement.classList.remove('success');
|
|
241
|
+
if (messageContainerElement) {
|
|
242
|
+
messageContainerElement.textContent = 'Invalid selection';
|
|
243
|
+
messageContainerElement.classList.add('error');
|
|
244
|
+
messageContainerElement.classList.remove('hidden');
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
syncInputElementWithModel(inputElement, model, fieldName, messageContainerElement, optionList) {
|
|
237
250
|
if (model.isLoaded) {
|
|
238
251
|
let fieldValue = model.value[fieldName];
|
|
252
|
+
this.verifyValue(fieldValue, optionList, inputElement, messageContainerElement);
|
|
239
253
|
this.updateInputElement(inputElement, fieldValue);
|
|
240
254
|
}
|
|
241
255
|
let stopSaving = this.saveInputElementOnEdit(inputElement, model, fieldName, messageContainerElement);
|
|
@@ -245,6 +259,7 @@ class ModelInput extends SocketConsumer {
|
|
|
245
259
|
let hasFocus = document.activeElement === this.inputElement;
|
|
246
260
|
if (event.resourceField !== fieldName || (hasFocus && !event.isRemote)) continue;
|
|
247
261
|
let fieldValue = model.value[fieldName];
|
|
262
|
+
this.verifyValue(fieldValue, optionList, inputElement, messageContainerElement);
|
|
248
263
|
this.updateInputElement(inputElement, fieldValue);
|
|
249
264
|
}
|
|
250
265
|
})();
|
package/package.json
CHANGED
package/styles.css
CHANGED
|
@@ -26,12 +26,12 @@ input[type=text]:focus,input[type=password]:focus,input[type=number]:focus,selec
|
|
|
26
26
|
outline-color: #00a5e5;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
input[type=text].error
|
|
29
|
+
input[type=text].error,input[type=password].error,input[type=number].error,select.error,textarea.error {
|
|
30
30
|
border-color: #ff0000;
|
|
31
31
|
outline-color: #ff0000;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
input[type=text].warning
|
|
34
|
+
input[type=text].warning,input[type=password].warning,input[type=number].warning,select.warning,textarea.warning {
|
|
35
35
|
border-color: #ee9900;
|
|
36
36
|
outline-color: #ee9900;
|
|
37
37
|
}
|