neo.mjs 4.0.79 → 4.0.82
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.
@@ -42,6 +42,13 @@ class MainContainer extends ConfigurationViewport {
|
|
42
42
|
labelText: 'disabled',
|
43
43
|
listeners: {change: me.onConfigChange.bind(me, 'disabled')},
|
44
44
|
style : {marginTop: '10px'}
|
45
|
+
}, {
|
46
|
+
module : TextField,
|
47
|
+
clearable: true,
|
48
|
+
labelText: 'error',
|
49
|
+
listeners: {change: me.onConfigChange.bind(me, 'error')},
|
50
|
+
reference: 'error-field',
|
51
|
+
value : me.exampleComponent.error
|
45
52
|
}, {
|
46
53
|
module : CheckBox,
|
47
54
|
checked : me.exampleComponent.hideLabel,
|
@@ -157,7 +164,14 @@ class MainContainer extends ConfigurationViewport {
|
|
157
164
|
labelWidth : 70,
|
158
165
|
minLength : 3,
|
159
166
|
value : 'Hello World',
|
160
|
-
width : 200
|
167
|
+
width : 200,
|
168
|
+
|
169
|
+
listeners: {
|
170
|
+
change(value) {
|
171
|
+
this.down({reference: 'error-field'}).clear();
|
172
|
+
},
|
173
|
+
scope: this
|
174
|
+
}
|
161
175
|
});
|
162
176
|
}
|
163
177
|
}
|
package/package.json
CHANGED
@@ -56,6 +56,7 @@
|
|
56
56
|
&.label-inline {
|
57
57
|
display : block;
|
58
58
|
font-size: 14px;
|
59
|
+
height : inherit;
|
59
60
|
position : relative;
|
60
61
|
|
61
62
|
&.neo-focus {
|
@@ -108,7 +109,7 @@
|
|
108
109
|
|
109
110
|
.neo-label-wrapper {
|
110
111
|
display : flex;
|
111
|
-
height :
|
112
|
+
height : 27px;
|
112
113
|
position: absolute;
|
113
114
|
width : 100%;
|
114
115
|
|
package/src/form/Container.mjs
CHANGED
@@ -156,11 +156,11 @@ class Container extends BaseContainer {
|
|
156
156
|
* Updates the invalid state for all fields, which have updateValidationIndicators() implemented.
|
157
157
|
* This can be useful for create entity forms which show up "clean", when pressing a submit button.
|
158
158
|
*/
|
159
|
-
|
159
|
+
validate() {
|
160
160
|
let fields = this.getFields();
|
161
161
|
|
162
162
|
fields.forEach(item => {
|
163
|
-
item.
|
163
|
+
item.validate?.(false);
|
164
164
|
});
|
165
165
|
}
|
166
166
|
}
|
package/src/form/field/Base.mjs
CHANGED
@@ -68,6 +68,15 @@ class Base extends Component {
|
|
68
68
|
reset(value) {
|
69
69
|
this.value = value;
|
70
70
|
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Checks for client-side field errors
|
74
|
+
* @param {Boolean} silent=true
|
75
|
+
* @returns {Boolean} Returns true in case there are no client-side errors
|
76
|
+
*/
|
77
|
+
validate(silent=true) {
|
78
|
+
return true;
|
79
|
+
}
|
71
80
|
}
|
72
81
|
|
73
82
|
/**
|
@@ -99,7 +99,7 @@ class Number extends Text {
|
|
99
99
|
* @protected
|
100
100
|
*/
|
101
101
|
afterSetMaxValue(value, oldValue) {
|
102
|
-
this.
|
102
|
+
this.validate(); // silent
|
103
103
|
this.changeInputElKey('max', value);
|
104
104
|
}
|
105
105
|
|
@@ -110,7 +110,7 @@ class Number extends Text {
|
|
110
110
|
* @protected
|
111
111
|
*/
|
112
112
|
afterSetMinValue(value, oldValue) {
|
113
|
-
this.
|
113
|
+
this.validate(); // silent
|
114
114
|
this.changeInputElKey('min', value);
|
115
115
|
}
|
116
116
|
|
package/src/form/field/Text.mjs
CHANGED
@@ -236,7 +236,7 @@ class Text extends Base {
|
|
236
236
|
* @protected
|
237
237
|
*/
|
238
238
|
afterSetError(value, oldValue) {
|
239
|
-
this.
|
239
|
+
this.updateError(value);
|
240
240
|
}
|
241
241
|
|
242
242
|
/**
|
@@ -410,7 +410,7 @@ class Text extends Base {
|
|
410
410
|
* @protected
|
411
411
|
*/
|
412
412
|
afterSetMaxLength(value, oldValue) {
|
413
|
-
this.
|
413
|
+
this.validate(); // silent
|
414
414
|
this.changeInputElKey('maxlength', value);
|
415
415
|
}
|
416
416
|
|
@@ -421,7 +421,7 @@ class Text extends Base {
|
|
421
421
|
* @protected
|
422
422
|
*/
|
423
423
|
afterSetMinLength(value, oldValue) {
|
424
|
-
this.
|
424
|
+
this.validate(); // silent
|
425
425
|
this.changeInputElKey('minlength', value);
|
426
426
|
}
|
427
427
|
|
@@ -474,7 +474,7 @@ class Text extends Base {
|
|
474
474
|
* @protected
|
475
475
|
*/
|
476
476
|
afterSetRequired(value, oldValue) {
|
477
|
-
this.
|
477
|
+
this.validate(); // silent
|
478
478
|
this.changeInputElKey('required', value ? value : null);
|
479
479
|
}
|
480
480
|
|
@@ -570,7 +570,7 @@ class Text extends Base {
|
|
570
570
|
}
|
571
571
|
|
572
572
|
NeoArray[me.originalConfig.value !== value ? 'add' : 'remove'](me._cls, 'neo-is-dirty');
|
573
|
-
me.
|
573
|
+
me.validate(); // silent
|
574
574
|
|
575
575
|
me.vdom = vdom;
|
576
576
|
|
@@ -845,28 +845,7 @@ class Text extends Base {
|
|
845
845
|
* @returns {Boolean}
|
846
846
|
*/
|
847
847
|
isValid() {
|
848
|
-
|
849
|
-
maxLength = me.maxLength,
|
850
|
-
minLength = me.minLength,
|
851
|
-
value = me.value,
|
852
|
-
valueLength = value?.toString().length;
|
853
|
-
|
854
|
-
if (me.required && (!value || valueLength < 1)) {
|
855
|
-
me._error = 'Required';
|
856
|
-
return false;
|
857
|
-
}
|
858
|
-
|
859
|
-
if (Neo.isNumber(maxLength) && valueLength > maxLength) {
|
860
|
-
me._error = `Max length violation: ${valueLength} / ${maxLength}`;
|
861
|
-
return false;
|
862
|
-
}
|
863
|
-
|
864
|
-
if (Neo.isNumber(minLength) && valueLength < minLength) {
|
865
|
-
me._error = `Min length violation: ${valueLength} / ${minLength}`;
|
866
|
-
return false;
|
867
|
-
}
|
868
|
-
|
869
|
-
return super.isValid();
|
848
|
+
return this.error?.length > 0 ? false : super.isValid();
|
870
849
|
}
|
871
850
|
|
872
851
|
/**
|
@@ -919,7 +898,7 @@ class Text extends Base {
|
|
919
898
|
centerBorderEl = me.getCenterBorderEl(), // labelPosition: 'inline'
|
920
899
|
vdom = me.vdom;
|
921
900
|
|
922
|
-
me.
|
901
|
+
me.validate(); // silent
|
923
902
|
|
924
903
|
NeoArray.remove(me._cls, 'neo-focus');
|
925
904
|
|
@@ -1017,6 +996,36 @@ class Text extends Base {
|
|
1017
996
|
});
|
1018
997
|
}
|
1019
998
|
|
999
|
+
/**
|
1000
|
+
@param {String|null} value
|
1001
|
+
@param {Boolean} silent=false
|
1002
|
+
*/
|
1003
|
+
updateError(value, silent=false) {
|
1004
|
+
let me = this,
|
1005
|
+
vdom = me.vdom,
|
1006
|
+
errorNode, isValid;
|
1007
|
+
|
1008
|
+
if (!(me.validBeforeMount && !me.mounted)) {
|
1009
|
+
isValid = !value || value === '';
|
1010
|
+
|
1011
|
+
NeoArray[!isValid ? 'add' : 'remove'](me._cls, 'neo-invalid');
|
1012
|
+
|
1013
|
+
errorNode = VDomUtil.findVdomChild(this.vdom, {cls: 'neo-textfield-error'}).vdom;
|
1014
|
+
|
1015
|
+
if (!isValid) {
|
1016
|
+
errorNode.html = me.error;
|
1017
|
+
} else {
|
1018
|
+
delete errorNode.html;
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
errorNode.removeDom = isValid;
|
1022
|
+
|
1023
|
+
if (!silent) {
|
1024
|
+
me.vdom = vdom;
|
1025
|
+
}
|
1026
|
+
}
|
1027
|
+
}
|
1028
|
+
|
1020
1029
|
/**
|
1021
1030
|
* Calculates the new inputWidth based on the labelWidth & total width
|
1022
1031
|
* @protected
|
@@ -1057,27 +1066,43 @@ class Text extends Base {
|
|
1057
1066
|
}
|
1058
1067
|
|
1059
1068
|
/**
|
1069
|
+
* Checks for client-side field errors
|
1060
1070
|
* @param {Boolean} silent=true
|
1071
|
+
* @returns {Boolean} Returns true in case there are no client-side errors
|
1061
1072
|
*/
|
1062
|
-
|
1063
|
-
let me
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1073
|
+
validate(silent=true) {
|
1074
|
+
let me = this,
|
1075
|
+
errorField = silent ? '_error' : 'error',
|
1076
|
+
maxLength = me.maxLength,
|
1077
|
+
minLength = me.minLength,
|
1078
|
+
required = me.required,
|
1079
|
+
returnValue = true,
|
1080
|
+
value = me.value,
|
1081
|
+
valueLength = value?.toString().length,
|
1082
|
+
isEmpty = !value || valueLength < 1;
|
1083
|
+
|
1084
|
+
if (required && isEmpty) {
|
1085
|
+
me[errorField] = 'Required';
|
1086
|
+
returnValue = false;
|
1087
|
+
} else if (Neo.isNumber(maxLength) && valueLength > maxLength) {
|
1088
|
+
if (required || !isEmpty) {
|
1089
|
+
me[errorField] = `Max length violation: ${valueLength} / ${maxLength}`;
|
1090
|
+
returnValue = false;
|
1091
|
+
}
|
1092
|
+
} else if (Neo.isNumber(minLength) && valueLength < minLength) {
|
1093
|
+
if (required || !isEmpty) {
|
1094
|
+
me[errorField] = `Min length violation: ${valueLength} / ${minLength}`;
|
1095
|
+
returnValue = false;
|
1096
|
+
}
|
1097
|
+
}
|
1071
1098
|
|
1072
|
-
|
1099
|
+
if (returnValue) {
|
1100
|
+
me[errorField] = null;
|
1101
|
+
}
|
1073
1102
|
|
1074
|
-
|
1075
|
-
errorNode.removeDom = isValid;
|
1103
|
+
silent && me.updateError(me[errorField], true);
|
1076
1104
|
|
1077
|
-
|
1078
|
-
me.vdom = vdom;
|
1079
|
-
}
|
1080
|
-
}
|
1105
|
+
return !returnValue ? false : super.validate(silent);
|
1081
1106
|
}
|
1082
1107
|
}
|
1083
1108
|
|