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

Method create_element

webiojs/src/handlers/input.ts:155–281  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153
154
155 create_element(): JQuery {
156 let tpl = `
157 <div class="card" style="display: none">
158 <h5 class="card-header">{{label}}</h5>
159 <div class="card-body">
160 <form>
161 <div class="input-container"></div>
162 <div class="ws-form-submit-btns">
163 <button type="submit" class="btn btn-primary">${t("submit")}</button>
164 <button type="reset" class="btn btn-warning">${t("reset")}</button>
165 {{#cancelable}}<button type="button" class="pywebio_cancel_btn btn btn-danger">${t("cancel")}</button>{{/cancelable}}
166 </div>
167 </form>
168 </div>
169 </div>`;
170 let that = this;
171
172 const html = Mustache.render(tpl, {label: this.spec.label, cancelable: this.spec.cancelable});
173 let element = $(html);
174
175 element.find('.pywebio_cancel_btn').on('click', function (e) {
176 element.find('button').prop("disabled", true);
177 that.session.send_message({
178 event: "from_cancel",
179 task_id: that.task_id,
180 data: null
181 });
182 });
183
184 // 隐藏默认的"提交"/"重置"按钮
185 if (this.spec.inputs.length && this.spec.inputs[this.spec.inputs.length - 1].type === 'actions') {
186 for (let btn of this.spec.inputs[this.spec.inputs.length - 1].buttons) {
187 if (btn.type === 'submit') {
188 element.find('.ws-form-submit-btns').hide();
189 break;
190 }
191 }
192 }
193
194 // 输入控件创建
195 let body = element.find('.input-container');
196 for (let idx in this.spec.inputs) {
197 let input_spec = this.spec.inputs[idx];
198 if (!(input_spec.type in FormController.input_items))
199 throw new Error(`Unknown input type '${input_spec.type}'`);
200 let item_class = FormController.input_items[input_spec.type];
201 let item = new item_class(input_spec, this.task_id, (event, input_item) => {
202 this.session.send_message({
203 event: "input_event",
204 task_id: this.task_id,
205 data: {
206 event_name: event,
207 name: input_spec.name,
208 value: input_item.get_value()
209 }
210 });
211 });
212 this.name2input[input_spec.name] = item;

Callers 1

handle_messageMethod · 0.95

Calls 13

tFunction · 0.90
error_alertFunction · 0.90
serialize_fileFunction · 0.90
serialize_jsonFunction · 0.90
appendMethod · 0.80
pushMethod · 0.80
make_progressMethod · 0.80
send_messageMethod · 0.65
send_bufferMethod · 0.65
$Function · 0.50
get_valueMethod · 0.45
on_resetMethod · 0.45

Tested by

no test coverage detected