Skip to content

Commit b73e061

Browse files
committed
fix: textarea(code=True, required=True) can't submit
1 parent 238aa0e commit b73e061

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

webiojs/src/models/input/textarea.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {InputItem} from "./base";
22
import {deep_copy, make_set} from "../../utils"
33
import {config as appConfig} from "../../state";
4+
import {t} from "../../i18n";
45

56

67
const textarea_input_tpl = `
@@ -57,8 +58,11 @@ export class Textarea extends InputItem {
5758
}
5859

5960
// 将额外的html参数加到input标签上
60-
const ignore_keys = make_set(['value', 'type', 'label', 'invalid_feedback', 'valid_feedback',
61+
let ignore_keys = make_set(['value', 'type', 'label', 'invalid_feedback', 'valid_feedback',
6162
'help_text', 'rows', 'code', 'onchange']);
63+
if (spec.code && spec.required){
64+
ignore_keys['required'] = '';
65+
}
6266
for (let key in this.spec) {
6367
if (key in ignore_keys) continue;
6468
input_elem.attr(key, this.spec[key]);
@@ -103,6 +107,17 @@ export class Textarea extends InputItem {
103107
return this.element.find('textarea').val();
104108
};
105109

110+
check_valid(): boolean {
111+
if (this.code_mirror && this.spec.required && !this.get_value()) {
112+
this.update_input_helper(-1, {
113+
'valid_status': false,
114+
'invalid_feedback': "Please fill out this field.",
115+
});
116+
return false;
117+
}
118+
return true;
119+
}
120+
106121
after_show(first_show: boolean): any {
107122
if (first_show && this.spec.code) {
108123
this.code_mirror = CodeMirror.fromTextArea(this.element.find('textarea')[0], this.code_mirror_config);

0 commit comments

Comments
 (0)