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

Method create_element

webiojs/src/models/input/slider.ts:24–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22 }
23
24 create_element(): JQuery {
25 let spec = deep_copy(this.spec);
26 spec['id_name'] = spec.name + '-' + Math.floor(Math.random() * Math.floor(9999));
27
28 const html = Mustache.render(slider_input_tpl, spec);
29 this.element = $(html);
30 let input_elem = this.element.find('input[type="range"]');
31
32 const ignore_keys = make_set(['value', 'step', 'type', 'label', 'invalid_feedback', 'valid_feedback',
33 'help_text', 'min_value', 'max_value', 'id_name', 'name', 'float', 'onchange', 'onblur']);
34 for (let key in this.spec) {
35 if (key in ignore_keys) continue;
36 input_elem.attr(key, this.spec[key]);
37 }
38
39 let range_value = this.element.find('.form-control-range-value');
40 range_value.text(
41 this.spec['float'] ? this.get_value().toFixed(2) : this.get_value()
42 );
43 input_elem.on("input", (e) => {
44 range_value.text(
45 this.spec['float'] ? this.get_value().toFixed(2) : this.get_value()
46 );
47 });
48
49
50 if (spec.onblur) {
51 // blur事件时,发送当前值到服务器
52 input_elem.on("blur", (e) => {
53 this.on_input_event("blur", this);
54 });
55 }
56 if (spec.onchange) {
57 input_elem.on("change", (e) => {
58 this.on_input_event("change", this);
59 });
60 }
61
62 return this.element;
63 }
64
65 update_input(spec: any): any {
66 let attributes = spec.attributes;

Callers

nothing calls this directly

Calls 4

get_valueMethod · 0.95
deep_copyFunction · 0.90
make_setFunction · 0.90
$Function · 0.50

Tested by

no test coverage detected