saasufy-components 3.5.0 → 3.6.1

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 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
- let optionElements = options
173
- .split(',')
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
- syncInputElementWithModel(inputElement, model, fieldName, messageContainerElement) {
237
+ verifyValue(fieldValue, optionList, inputElement, messageContainerElement) {
238
+ if (optionList && fieldValue != null && !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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
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:focus,input[type=password].error:focus,input[type=number].error:focus,select.error:focus,textarea.error:focus {
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:focus,input[type=password].warning:focus,input[type=number].warning:focus,select.warning:focus,textarea.warning:focus {
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
  }