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

Method update_input

webiojs/src/models/input/select.ts:84–114  ·  view source on GitHub ↗
(spec: any)

Source from the content-addressed store, hash-verified

82 }
83
84 update_input(spec: any): any {
85 let attributes = spec.attributes;
86
87 if ('options' in attributes) {
88 const opts_html = Mustache.render(options_tpl, {options: attributes.options});
89 this.element.find('select').empty().append(opts_html);
90 this.setup_select_options(this.element, attributes.options);
91 delete attributes['options'];
92 }
93
94 if ('value' in attributes) {
95 this.element.find('option').prop('selected', false);
96 let values: any[] = attributes.value;
97 if (!this.spec.multiple) {
98 values = [attributes.value];
99 }
100 this.element.find('option').each(function (index) {
101 let item_val = JSON.parse($(this).val() as string);
102 if (values.indexOf(item_val) != -1) {
103 $(this).prop('selected', true);
104 }
105 });
106 if (this.use_bootstrap_select) {
107 // @ts-ignore
108 this.element.find('select').selectpicker('render');
109 }
110 delete attributes['value'];
111 }
112
113 this.update_input_helper(-1, attributes);
114 }
115
116 on_reset(e: any) {
117 // need to wait some time to get the select element be reset, and then update `selectpicker`

Callers

nothing calls this directly

Calls 4

setup_select_optionsMethod · 0.95
appendMethod · 0.80
update_input_helperMethod · 0.80
$Function · 0.50

Tested by

no test coverage detected