MCPcopy Index your code
hub / github.com/json-editor/json-editor / preBuild

Method preBuild

src/editors/select.js:77–175  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75 }
76
77 preBuild () {
78 this.input_type = 'select'
79 this.enum_options = []
80 this.enum_values = []
81 this.enum_display = []
82 let i
83 let callback
84
85 this.hasPlaceholderOption = this.schema?.options?.has_placeholder_option || false
86 this.placeholderOptionText = this.schema?.options?.placeholder_option_text || ' '
87
88 /* Const value */
89 if (this.enforceConst && this.schema.const) {
90 const value = this.schema.const
91 this.enum_options = [`${value}`]
92 this.enum_display = [`${this.translateProperty(value) || value}`]
93 this.enum_values = [this.typecast(value)]
94 /* Enum options enumerated */
95 } else if (this.schema.enum) {
96 const display = (this.schema.options && this.schema.options.enum_titles) || []
97
98 this.schema.enum.forEach((option, i) => {
99 this.enum_options[i] = `${option}`
100 this.enum_display[i] = `${this.translateProperty(display[i]) || option}`
101 this.enum_values[i] = this.typecast(option)
102 })
103 /* Boolean */
104 } else if (this.schema.type === 'boolean') {
105 this.enum_display = (this.schema.options && this.schema.options.enum_titles) || ['true', 'false']
106 this.enum_options = ['1', '']
107 this.enum_values = [true, false]
108
109 if (!this.isRequired()) {
110 this.enum_display.unshift(' ')
111 this.enum_options.unshift('undefined')
112 this.enum_values.unshift(undefined)
113 }
114 /* Dynamic Enum */
115 } else if (this.schema.enumSource) {
116 this.enumSource = []
117 this.enum_display = []
118 this.enum_options = []
119 this.enum_values = []
120
121 /* Shortcut declaration for using a single array */
122 if (!(Array.isArray(this.schema.enumSource))) {
123 if (this.schema.enumValue) {
124 this.enumSource = [
125 {
126 source: this.schema.enumSource,
127 value: this.schema.enumValue
128 }
129 ]
130 } else {
131 this.enumSource = [
132 {
133 source: this.schema.enumSource
134 }

Callers

nothing calls this directly

Calls 5

typecastMethod · 0.95
extendFunction · 0.90
isRequiredMethod · 0.80
expandCallbacksMethod · 0.80
compileTemplateMethod · 0.80

Tested by

no test coverage detected