glib-web 3.8.0 → 3.8.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.
@@ -20,51 +20,29 @@ export default {
20
20
  return {
21
21
  otpLength: this.spec.length,
22
22
  otp: new Array(6).fill(''),
23
- hint: false
23
+ hint: false,
24
+ isValueChanged: false
24
25
  };
25
26
  },
26
- created() {
27
- if (this.spec.value) {
28
- const valueString = this.spec.value.toString();
29
-
30
- for (let i = 0; i < this.otpLength && i < valueString.length; i++) {
31
- this.otp[i] = valueString[i];
32
- }
33
-
34
- }
35
-
36
- },
37
- mounted() {
38
- if (this.spec.valueIf) {
39
- const valueString = this.fieldModel.toString();
40
-
41
- for (let i = 0; i < this.otpLength && i < valueString.length; i++) {
42
- this.otp[i] = valueString[i];
43
- }
44
- }
45
- },
46
27
  watch: {
47
- fieldModel(newFieldModel) {
48
- let valueString = '';
49
-
50
- if (newFieldModel !== '') {
51
- valueString = isNaN(newFieldModel) ? '' : parseInt(newFieldModel).toString();
52
- }
53
- this.otp = [];
54
- for (let i = 0; i < valueString.length; i++) {
55
- this.otp[i] = valueString[i];
56
- }
57
-
28
+ fieldModel: {
29
+ handler(val) {
30
+ this.updateOtp(val)
31
+ },
32
+ immediate: true
58
33
  }
59
34
  },
60
35
  methods: {
61
36
  $ready() {
62
- if (this.spec.value) {
63
- const valueString = this.spec.value.toString();
37
+ this.updateOtp(this.fieldModel)
38
+ },
39
+ updateOtp(val) {
40
+ if (!val) return;
64
41
 
65
- for (let i = 0; i < this.otpLength && i < valueString.length; i++) {
66
- this.otp[i] = valueString[i];
67
- }
42
+ const valueString = isNaN(val) ? '' : parseInt(val).toString();
43
+ this.otp = [];
44
+ for (let i = 0; i < this.otpLength && i < valueString.length; i++) {
45
+ this.otp[i] = valueString[i];
68
46
  }
69
47
  },
70
48
  onInput(index) {
@@ -9,6 +9,8 @@ export default {
9
9
  fieldName: null,
10
10
  fieldModel: null,
11
11
  _show: true,
12
+ _watchers: [],
13
+ _isValueChanged: false,
12
14
  // Some components do not support null or empty string value, so we need to use an intermediary value.
13
15
  // See https://github.com/vuetifyjs/vuetify/issues/8876
14
16
  vuetifyEmptyString: "<EMPTY_STRING>"
@@ -57,33 +59,57 @@ export default {
57
59
  valueChanged = false;
58
60
  }
59
61
  this._linkFieldModels(valueChanged);
62
+ this._initConditional(oldSpec);
60
63
  }
61
64
  },
62
65
  immediate: true
63
66
  }
64
67
  },
65
- // watch showIf and valueIf
66
- mounted() {
67
- if (this.spec && this.spec.valueIf) {
68
- watchFieldModels(this.spec.valueIf, (value) => this.fieldModel = this.$sanitizeValue(this.$externalizeValue(value)));
69
- }
70
-
71
- if (this.spec && (this.spec.showIf || this.spec.loadIf)) {
72
- watchFieldModels(this.spec.showIf || this.spec.loadIf, (value) => {
73
- if (value) {
74
- this._show = true;
75
- } else {
76
- this._show = false;
77
- }
78
- });
79
- }
80
- },
81
68
  unmounted() {
82
69
  if (fieldModels[this.fieldName]) {
83
70
  delete fieldModels[this.fieldName];
84
71
  }
85
72
  },
86
73
  methods: {
74
+ _initConditional(oldSpec) {
75
+ // unreg old fieldName
76
+ if (oldSpec && fieldModels[oldSpec.name]) {
77
+ delete fieldModels[oldSpec.name];
78
+ }
79
+ // unreg watchers if there is
80
+ this._watchers.forEach(watcher => {
81
+ if (typeof watcher == Function) {
82
+ watcher();
83
+ }
84
+ });
85
+
86
+ let watcher1, watcher2;
87
+
88
+ // watch showIf & loadIf
89
+ if (this.spec && this.spec.valueIf) {
90
+ watcher1 = watchFieldModels(this.spec.valueIf, (value) => {
91
+ // prevent override spec.value
92
+ if (!this._isValueChanged && this.spec.value) {
93
+ this._isValueChanged = true;
94
+ return;
95
+ }
96
+
97
+ this.fieldModel = this.$sanitizeValue(this.$externalizeValue(value));
98
+ });
99
+ this._watchers.push(watcher1);
100
+ }
101
+
102
+ if (this.spec && (this.spec.showIf || this.spec.loadIf)) {
103
+ watcher2 = watchFieldModels(this.spec.showIf || this.spec.loadIf, (value) => {
104
+ if (value) {
105
+ this._show = true;
106
+ } else {
107
+ this._show = false;
108
+ }
109
+ });
110
+ this._watchers.push(watcher2);
111
+ }
112
+ },
87
113
  // TODO: Deprecated
88
114
  genericStyles(spec) {
89
115
  return this.$styles(spec);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glib-web",
3
- "version": "3.8.0",
3
+ "version": "3.8.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -41,4 +41,4 @@
41
41
  "prettier": "^1.18.2",
42
42
  "typescript": "^4.9.5"
43
43
  }
44
- }
44
+ }