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

Method create_element

webiojs/src/models/input/input.ts:38–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36 }
37
38 create_element(): JQuery {
39 let spec = deep_copy(this.spec);
40 const id_name = spec.name + '-' + Math.floor(Math.random() * Math.floor(9999));
41 spec['id_name'] = id_name;
42 if (spec['type'] == 'float') spec['type'] = 'text';
43
44 let html = Mustache.render(common_input_tpl, spec);
45
46 this.element = $(html);
47
48 this.element.find(`#${id_name}_action_btn`).on('click', function (e) {
49 let btn = $(this);
50 state.CurrentSession.send_message({
51 event: "callback",
52 task_id: btn.data('callbackid') as string,
53 data: null
54 });
55 });
56
57 let input_elem = this.element.find('input');
58 if (spec.onblur) {
59 // blur事件时,发送当前值到服务器
60 input_elem.on("blur", (e) => {
61 if (this.get_value())
62 this.on_input_event("blur", this);
63 });
64 }
65
66 input_elem.on("input", (e) => {
67 this.rectify_input()
68 if (spec.onchange) {
69 this.on_input_event("change", this);
70 }
71 });
72
73 // 将额外的html参数加到input标签上
74 const ignore_keys = make_set(['action', 'type', 'label', 'invalid_feedback', 'valid_feedback', 'help_text',
75 'options', 'datalist', 'multiple', 'onchange', 'onblur']);
76 for (let key in this.spec) {
77 if (key in ignore_keys) continue;
78 input_elem.attr(key, this.spec[key]);
79 }
80
81 return this.element;
82 }
83
84 rectify_input() {
85 let val = '' + this.element.find('input').val() as string;

Callers 1

pin.tsFile · 0.45

Calls 6

get_valueMethod · 0.95
rectify_inputMethod · 0.95
deep_copyFunction · 0.90
make_setFunction · 0.90
send_messageMethod · 0.65
$Function · 0.50

Tested by

no test coverage detected