@cybertale/form 0.1.4 → 0.1.5

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cybertale/form",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "ECS interface for Web Development, CyberTale edition.",
5
5
  "author": "Joso Marich <jspmari@proton.me>",
6
6
  "license": "GPL-3.0-only",
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div :class="object?.Stats[statTypeEnum.Design].Data">
3
3
  <input class="form-check-input mt-0" type="checkbox"
4
- :checked="!!object?.Stats[statTypeEnum.Value].Data"
4
+ :checked="getValue(statTypeEnum.Value, statTypeEnum.ValueIndices)"
5
5
  :id="object?.Stats[statTypeEnum.Tag].Data"
6
6
  :required="attributeCheck(statTypeEnum.Required)"
7
7
  :disabled="attributeCheck(statTypeEnum.Disabled)"
@@ -42,6 +42,28 @@ export default class CheckBoxComponent extends Vue {
42
42
  return ''
43
43
  }
44
44
 
45
+ getValue (statEnum: number, indexStatTypeEnum = StatTypeEnum.Option) : string {
46
+ if (this.object.Stats[statEnum]) {
47
+ if (this.object.Stats[indexStatTypeEnum] && this.object.Stats[statEnum] && this.isJSON(this.object.Stats[statEnum].Data)) {
48
+ const data = JSON.parse(this.object.Stats[statEnum].Data)
49
+ return data[Number(this.object.Stats[indexStatTypeEnum].Data)]
50
+ } else {
51
+ return this.object.Stats[statEnum].Data
52
+ }
53
+ }
54
+ return ''
55
+ }
56
+
57
+ isJSON (str: string): boolean {
58
+ let temp = null
59
+ try {
60
+ temp = JSON.parse(str)
61
+ } catch (e) {
62
+ return false
63
+ }
64
+ return Array.isArray(temp)
65
+ }
66
+
45
67
  validate () : string {
46
68
  if (this.object.Stats[this.statTypeEnum.IsValid] === undefined) { return '' }
47
69
  if (this.object.Stats[this.statTypeEnum.IsValid].Data === '') { return '' }