@cybertale/form 0.1.1 → 0.1.3
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/package.json
CHANGED
|
@@ -4,24 +4,26 @@
|
|
|
4
4
|
:required="attributeCheck(statTypeEnum.Required)"
|
|
5
5
|
:disabled="attributeCheck(statTypeEnum.Disabled)"
|
|
6
6
|
:type="returnIfExists(statTypeEnum.ElementType)"
|
|
7
|
-
:value="`${object?.Stats[statTypeEnum.Value].Data !== null?object.Stats[statTypeEnum.Value].Data.name === undefined?valueName:object.Stats[statTypeEnum.Value].Data.name:''}`"
|
|
7
|
+
:value="`${object?.Stats[statTypeEnum.Value].Data !== null ? object.Stats[statTypeEnum.Value].Data.name === undefined ? valueName : object.Stats[statTypeEnum.Value].Data.name : ''}`"
|
|
8
8
|
:placeholder="returnIfExists(statTypeEnum.Placeholder)"
|
|
9
9
|
@input="inputEvent(object as ObjectTemplate, $event.target.value)">
|
|
10
|
-
<datalist :id="object.Stats[statTypeEnum.BelongsTo].Data" v-if="
|
|
11
|
-
<option v-for="(
|
|
10
|
+
<datalist :id="object.Stats[statTypeEnum.BelongsTo].Data" v-if="displayOptions">
|
|
11
|
+
<option v-for="(option, index) in options" :key="index" :value="option.name">{{ option.name }}</option>
|
|
12
12
|
</datalist>
|
|
13
13
|
<div class="invalid-feedback order-1">{{ returnIfExists(statTypeEnum.ErrorMessage) }}</div>
|
|
14
14
|
</template>
|
|
15
|
-
|
|
16
15
|
<script lang="ts">
|
|
17
16
|
import { Options, Vue } from 'vue-class-component'
|
|
18
17
|
import { ObjectTemplate, ObjectType, ObjectTypeEnum, RegionEnum, RegionType, StatTypeEnum } from '@cybertale/interface'
|
|
18
|
+
import http from '@/http-common'
|
|
19
19
|
|
|
20
20
|
interface Option {
|
|
21
21
|
id: number;
|
|
22
22
|
name: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
const MIN_SEARCH_LENGTH = 3;
|
|
26
|
+
|
|
25
27
|
@Options({
|
|
26
28
|
computed: {
|
|
27
29
|
ObjectTemplate () {
|
|
@@ -39,8 +41,8 @@ export default class DataListComponent extends Vue {
|
|
|
39
41
|
regionType = RegionType
|
|
40
42
|
regionEnum = RegionEnum
|
|
41
43
|
object!: ObjectTemplate
|
|
42
|
-
|
|
43
|
-
options: Option[] =
|
|
44
|
+
displayOptions = false
|
|
45
|
+
options: Option[] = []
|
|
44
46
|
|
|
45
47
|
returnIfExists (tag: number): string {
|
|
46
48
|
if (this.object.Stats[tag]) {
|
|
@@ -49,6 +51,26 @@ export default class DataListComponent extends Vue {
|
|
|
49
51
|
return ''
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
async created() {
|
|
55
|
+
await this.fetchOptions();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Extract the logic for fetching options data into a separate method
|
|
59
|
+
async fetchOptions() {
|
|
60
|
+
try {
|
|
61
|
+
const parsedObject: { link?: string } = JSON.parse(this.object.Stats[this.statTypeEnum.ItemList].Data)[0];
|
|
62
|
+
if (parsedObject.link) {
|
|
63
|
+
const response = await http.get(parsedObject.link + '/' + this.object.Stats[this.statTypeEnum.Name].Data);
|
|
64
|
+
this.options = response.data;
|
|
65
|
+
this.displayOptions = true;
|
|
66
|
+
} else {
|
|
67
|
+
this.options = JSON.parse(this.object.Stats[this.statTypeEnum.ItemList].Data);
|
|
68
|
+
}
|
|
69
|
+
} catch (error: any) {
|
|
70
|
+
console.error('Error fetching data:', error.message);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
52
74
|
getValue (statEnum: number, indexStatTypeEnum = StatTypeEnum.Option) : string {
|
|
53
75
|
if (this.object.Stats[statEnum]) {
|
|
54
76
|
if (this.object.Stats[indexStatTypeEnum] && this.object.Stats[statEnum] && this.isJSON(this.object.Stats[statEnum].Data)) {
|
|
@@ -61,16 +83,6 @@ export default class DataListComponent extends Vue {
|
|
|
61
83
|
return ''
|
|
62
84
|
}
|
|
63
85
|
|
|
64
|
-
isJSON (str: string): boolean {
|
|
65
|
-
let temp = null
|
|
66
|
-
try {
|
|
67
|
-
temp = JSON.parse(str)
|
|
68
|
-
} catch (e) {
|
|
69
|
-
return false
|
|
70
|
-
}
|
|
71
|
-
return Array.isArray(temp)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
86
|
get valueName (): string {
|
|
75
87
|
const temp = this.options.find((option: any) => option.id === this.getValue(StatTypeEnum.Value, StatTypeEnum.ValueIndices))
|
|
76
88
|
if (!temp) { return this.getValue(StatTypeEnum.Value, StatTypeEnum.ValueIndices) }
|
|
@@ -93,7 +105,7 @@ export default class DataListComponent extends Vue {
|
|
|
93
105
|
}
|
|
94
106
|
|
|
95
107
|
inputEvent (object: ObjectTemplate, value: string) : void {
|
|
96
|
-
this.
|
|
108
|
+
this.displayOptions = value.length >= MIN_SEARCH_LENGTH
|
|
97
109
|
this.regionType.RegionTypes[object.Region].ObjectTypes[object.ObjectEnum].ChooseSubType(object, value)
|
|
98
110
|
}
|
|
99
111
|
|
|
@@ -101,9 +113,20 @@ export default class DataListComponent extends Vue {
|
|
|
101
113
|
if (this.object.Stats[this.statTypeEnum.Value] === undefined || id === undefined) { return false }
|
|
102
114
|
return this.object.Stats[this.statTypeEnum.Value].Data === id.toString()
|
|
103
115
|
}
|
|
116
|
+
|
|
117
|
+
isJSON (str: string): boolean {
|
|
118
|
+
let temp = null
|
|
119
|
+
try {
|
|
120
|
+
temp = JSON.parse(str)
|
|
121
|
+
} catch (e) {
|
|
122
|
+
return false
|
|
123
|
+
}
|
|
124
|
+
return Array.isArray(temp)
|
|
125
|
+
}
|
|
126
|
+
|
|
104
127
|
}
|
|
105
|
-
</script>
|
|
106
128
|
|
|
129
|
+
</script>
|
|
107
130
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
108
131
|
<style scoped>
|
|
109
132
|
</style>
|