Skip to content

Commit 8c02602

Browse files
committed
fix #468: can't reset select()
1 parent 69e9304 commit 8c02602

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

webiojs/src/handlers/input.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,20 @@ class FormController {
214214
body.append(item.create_element());
215215
}
216216

217+
element.on('reset', 'form', function (e) {
218+
for (let name in that.name2input) {
219+
that.name2input[name].on_reset(e);
220+
}
221+
});
222+
217223
// submit event
218224
element.on('submit', 'form', function (e) {
219225
e.preventDefault(); // avoid to execute the actual submit of the form.
220226

221227
element.find('button').prop("disabled", true);
222228

223-
for (let name in that.name2input){
224-
if (!that.name2input[name].check_valid()){
229+
for (let name in that.name2input) {
230+
if (!that.name2input[name].check_valid()) {
225231
element.find('button').prop("disabled", false);
226232
return error_alert(t("error_in_input"));
227233
}

webiojs/src/models/input/base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export class InputItem {
4242

4343
}
4444

45+
// invoked when the form is reset
46+
on_reset(e: any) {
47+
}
48+
4549
/*
4650
* input_idx: 更新作用对象input标签的索引, -1 为不指定对象
4751
* attributes:更新值字典

webiojs/src/models/input/select.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ export class Select extends InputItem {
3939
// @ts-ignore
4040
this.element.find('select').selectpicker();
4141

42-
if(spec.onblur) {
42+
if (spec.onblur) {
4343
// blur事件时,发送当前值到服务器
4444
this.element.find('select').on("blur", (e) => {
4545
this.on_input_event("blur", this);
4646
});
4747
}
48-
if(spec.onchange){
48+
if (spec.onchange) {
4949
this.element.find('select').on("change", (e) => {
5050
this.on_input_event("change", this);
5151
});
@@ -102,6 +102,14 @@ export class Select extends InputItem {
102102
this.update_input_helper(-1, attributes);
103103
}
104104

105+
on_reset(e: any) {
106+
// need to wait some time to get the select element be reset, and then update `selectpicker`
107+
setTimeout(() => {
108+
// @ts-ignore
109+
this.element.find('select').selectpicker('render');
110+
}, 100)
111+
}
112+
105113
get_value(): any {
106114
let raw_val = this.element.find('select').val();
107115
if (this.spec.multiple) {

0 commit comments

Comments
 (0)