MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / create_element

Method create_element

webiojs/src/models/input/textarea.ts:42–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40 }
41
42 create_element() {
43 let that = this;
44
45 let spec = deep_copy(this.spec);
46 spec['id_name'] = spec.name + '-' + Math.floor(Math.random() * Math.floor(9999));
47 let html = Mustache.render(textarea_input_tpl, spec);
48 this.element = $(html);
49 let input_elem = this.element.find('textarea');
50
51 // blur事件时,发送当前值到服务器
52 // input_elem.on('blur', this.send_value_listener);
53 if (spec.onchange) {
54 input_elem.on("input", (e) => {
55 this.on_input_event("change", this);
56 });
57 }
58
59 // 将额外的html参数加到input标签上
60 let ignore_keys = make_set(['value', 'type', 'label', 'invalid_feedback', 'valid_feedback',
61 'help_text', 'rows', 'code', 'onchange']);
62 if (spec.code && spec.required) {
63 ignore_keys['required'] = '';
64 }
65 for (let key in this.spec) {
66 if (key in ignore_keys) continue;
67 input_elem.attr(key, this.spec[key]);
68 }
69 if (spec.code) {
70 if (spec.code === true) spec.code = {mode: 'text/plain'};
71 CodeMirror.modeURL = appConfig.codeMirrorModeURL;
72
73 for (let k in that.spec.code)
74 this.code_mirror_config[k] = that.spec.code[k];
75
76 // Get mode name by extension or MIME
77 let origin_mode = spec.code.mode || 'text/plain';
78 let mode_info = CodeMirror.findModeByExtension(origin_mode) || CodeMirror.findModeByMIME(origin_mode);
79 if (mode_info)
80 this.code_mirror_config.mode = mode_info.mode;
81
82 if (that.spec.readonly || that.spec.disabled)
83 this.code_mirror_config['readOnly'] = "nocursor";
84
85 if (this.code_mirror_config.theme && this.code_mirror_config.theme !== 'base16-light')
86 Textarea.load_codemirror_theme(this.code_mirror_config.theme);
87 }
88
89 return this.element;
90 };
91
92 update_input(spec: any) {
93 let attributes = spec.attributes;

Callers

nothing calls this directly

Calls 4

deep_copyFunction · 0.90
make_setFunction · 0.90
load_codemirror_themeMethod · 0.80
$Function · 0.50

Tested by

no test coverage detected