()
| 21 | } |
| 22 | |
| 23 | create_element(): JQuery { |
| 24 | for (let b of this.spec.buttons) b['btn_type'] = b.type === "submit" ? "submit" : "button"; |
| 25 | |
| 26 | this.spec.color = "primary"; // default button color |
| 27 | const html = Mustache.render(buttons_tpl, this.spec); |
| 28 | this.element = $(html); |
| 29 | let btns = this.element.find('button'); |
| 30 | for (let idx = 0; idx < this.spec.buttons.length; idx++) |
| 31 | btns.eq(idx).val(JSON.stringify(this.spec.buttons[idx].value)); |
| 32 | |
| 33 | let that = this; |
| 34 | this.element.find('button').on('click', function (e) { |
| 35 | let btn = $(this); |
| 36 | if (btn.data('type') === 'submit') { |
| 37 | // 不可以使用 btn.parents('form').submit(), 会导致input 的required属性失效 |
| 38 | that.submit_value = JSON.parse(btn.val() as string); |
| 39 | if(that.spec.onchange) // the `onchange` of spec will be only set in pin widget |
| 40 | that.on_input_event("change", that); |
| 41 | } else if (btn.data('type') === 'reset') { |
| 42 | btn.parents('form').trigger("reset"); |
| 43 | } else if (btn.data('type') === 'cancel') { |
| 44 | state.CurrentSession.send_message({ |
| 45 | event: "from_cancel", |
| 46 | task_id: that.task_id, |
| 47 | data: null |
| 48 | }); |
| 49 | } else { |
| 50 | console.error("`actions` input: unknown button type '%s'", btn.data('type')); |
| 51 | } |
| 52 | }); |
| 53 | |
| 54 | return this.element; |
| 55 | } |
| 56 | |
| 57 | update_input(spec: any): any { |
| 58 | let attributes = spec.attributes; |
nothing calls this directly
no test coverage detected