|
1 | 1 | import {InputItem} from "./base"; |
2 | 2 | import {deep_copy, make_set} from "../../utils" |
3 | 3 | import {config as appConfig} from "../../state"; |
| 4 | +import {t} from "../../i18n"; |
4 | 5 |
|
5 | 6 |
|
6 | 7 | const textarea_input_tpl = ` |
@@ -57,8 +58,11 @@ export class Textarea extends InputItem { |
57 | 58 | } |
58 | 59 |
|
59 | 60 | // 将额外的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', |
61 | 62 | 'help_text', 'rows', 'code', 'onchange']); |
| 63 | + if (spec.code && spec.required){ |
| 64 | + ignore_keys['required'] = ''; |
| 65 | + } |
62 | 66 | for (let key in this.spec) { |
63 | 67 | if (key in ignore_keys) continue; |
64 | 68 | input_elem.attr(key, this.spec[key]); |
@@ -103,6 +107,17 @@ export class Textarea extends InputItem { |
103 | 107 | return this.element.find('textarea').val(); |
104 | 108 | }; |
105 | 109 |
|
| 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 | + |
106 | 121 | after_show(first_show: boolean): any { |
107 | 122 | if (first_show && this.spec.code) { |
108 | 123 | this.code_mirror = CodeMirror.fromTextArea(this.element.find('textarea')[0], this.code_mirror_config); |
|
0 commit comments