1
0
Эх сурвалжийг харах

如果表单最后一个输入元素为actions组件,则隐藏默认的"提交"/"重置"按钮

wangweimin 5 жил өмнө
parent
commit
35227c6d76

+ 2 - 0
doc/spec.md

@@ -54,6 +54,8 @@ type=actions
     label
     name
     buttons 字典列表 {*value:, *label:, disabled}
+如果表单最后一个输入元素为actions组件,则隐藏默认的"提交"/"重置"按钮
+
 
 input_group:
     label: # todo change to label

+ 9 - 5
wsrepl/html/js/form.js

@@ -234,8 +234,10 @@
             <div class="card-body">
                 <form>
                     <div class="input-container"></div>
-                    <button type="submit" class="btn btn-primary">提交</button>
-                    <button type="reset" class="btn btn-warning">重置</button>
+                    <div class="ws-form-submit-btns">
+                        <button type="submit" class="btn btn-primary">提交</button>
+                        <button type="reset" class="btn btn-warning">重置</button>
+                    </div>
                 </form>
             </div>
         </div>`;
@@ -243,6 +245,10 @@
         const html = Mustache.render(tpl, {label: this.spec.label});
         this.element = $(html);
 
+        // 如果表单最后一个输入元素为actions组件,则隐藏默认的"提交"/"重置"按钮
+        if(this.spec.inputs.length && this.spec.inputs[this.spec.inputs.length-1].type==='actions')
+            this.element.find('.ws-form-submit-btns').hide();
+
         // 输入控件创建
         var body = this.element.find('.input-container');
         for (var idx in this.spec.inputs) {
@@ -498,7 +504,7 @@
     function ButtonsController(ws_client, coro_id, spec) {
         FormItemController.apply(this, arguments);
 
-        this.last_checked_value = undefined;  // 上次点击按钮的value
+        this.last_checked_value = null;  // 上次点击按钮的value
         this.create_element();
     }
 
@@ -516,7 +522,6 @@
 </div>`;
 
     ButtonsController.prototype.create_element = function () {
-        var spec = deep_copy(this.spec);
         const html = Mustache.render(buttons_tpl, this.spec);
         this.element = $(html);
 
@@ -525,7 +530,6 @@
         this.element.find('button').on('click', function (e) {
             var btn = $(this);
             that.last_checked_value = btn.val();
-            that.send_value_listener.apply(this, arguments);
         });
     };
 

+ 3 - 2
wsrepl/interact.py

@@ -186,7 +186,8 @@ def select(label, options, type=SELECT, *, multiple=None, valid_func=None, name=
     input_kwargs = dict(locals())
     input_kwargs['label'] = ''
     input_kwargs['__name__'] = select.__name__
-    input_kwargs.setdefault('autofocus', True)  # 如果没有设置autofocus参数,则开启参数
+    if type == SELECT:
+        input_kwargs.setdefault('autofocus', True)  # 如果没有设置autofocus参数,则开启参数
 
     allowed_type = {CHECKBOX, RADIO, SELECT}
     assert type in allowed_type, 'Input type not allowed.'
@@ -273,7 +274,7 @@ def input_group(label, inputs, valid_func=None):
 
     if all('autofocus' not in i for i in spec_inputs):  # 每一个输入项都没有设置autofocus参数
         for i in spec_inputs:
-            text_inputs = {TEXT, NUMBER, PASSWORD}  # todo update
+            text_inputs = {TEXT, NUMBER, PASSWORD, SELECT}  # todo update
             if i.get('type') in text_inputs:
                 i['autofocus'] = True
                 break