{"record":{"id":"26b734aca720dc36","repo":"dianping/cat","slug":"val-cannot-be-called-if-initselection-is-not-d","errorCode":null,"errorMessage":"val() cannot be called if initSelection() is not defined","messagePattern":"val\\(\\) cannot be called if initSelection\\(\\) is not defined","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/select2.js","lineNumber":3259,"sourceCode":"                this.updateSelection([]);\n                this.clearSearch();\n                if (triggerChange) {\n                    this.triggerChange({added: this.data(), removed: oldData});\n                }\n                return;\n            }\n\n            // val is a list of ids\n            this.setVal(val);\n\n            if (this.select) {\n                this.opts.initSelection(this.select, this.bind(this.updateSelection));\n                if (triggerChange) {\n                    this.triggerChange(this.buildChangeDetails(oldData, this.data()));\n                }\n            } else {\n                if (this.opts.initSelection === undefined) {\n                    throw new Error(\"val() cannot be called if initSelection() is not defined\");\n                }\n\n                this.opts.initSelection(this.opts.element, function(data){\n                    var ids=$.map(data, self.id);\n                    self.setVal(ids);\n                    self.updateSelection(data);\n                    self.clearSearch();\n                    if (triggerChange) {\n                        self.triggerChange(self.buildChangeDetails(oldData, self.data()));\n                    }\n                });\n            }\n            this.clearSearch();\n        },\n\n        // multi\n        onSortStart: function() {\n            if (this.select) {","sourceCodeStart":3241,"sourceCodeEnd":3277,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/select2.js#L3241-L3277","documentation":"Error \"val() cannot be called if initSelection() is not defined\" thrown in dianping/cat.","triggerScenarios":"Triggered when val() is called on a Select2 attached to an <input type='hidden'> without defining initSelection() to map ids to objects.","commonSituations":"See trigger scenarios.","solutions":["Define the initSelection option when attaching Select2 to a hidden input so val() can resolve ids to data.","Set data via select2('data', ...) instead of relying on val()."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}