Преглед изворни кода

maint: pin will expire when new pin with same name be output

Weimin Wang пре 4 година
родитељ
комит
3cbb4d86e3
3 измењених фајлова са 5 додато и 5 уклоњено
  1. 1 1
      pywebio/pin.py
  2. 2 2
      webiojs/src/i18n.ts
  3. 2 2
      webiojs/src/models/pin.ts

+ 1 - 1
pywebio/pin.py

@@ -74,7 +74,7 @@ The function of pin widget supports most of the parameters of the corresponding
 The following is the difference between the two in parameters:
 
  * The first parameter of pin widget function is always the name of the widget,
-   and the name needs to be unique throughout the session.
+   and if you output two pin widgets with the same name, the previous one will expire.
  * Pin functions don't support the ``on_change`` and ``validate`` callbacks, and the ``required`` parameter.
  * Pin functions have additional ``scope`` and ``position`` parameters for output control.
 

+ 2 - 2
webiojs/src/i18n.ts

@@ -14,7 +14,7 @@ const translations: { [lang: string]: { [msgid: string]: string } } = {
         "submit": "Submit",
         "reset": "Reset",
         "cancel": "Cancel",
-        "duplicated_pin_name": "App Error: Duplicated pin widget name '%1'",
+        "duplicated_pin_name": "This pin widget has expired (due to the output of a new pin widget with the same name ).",
     },
     "zh": {
         "disconnected_with_server": "与服务器连接已断开,请刷新页面重新操作",
@@ -25,7 +25,7 @@ const translations: { [lang: string]: { [msgid: string]: string } } = {
         "submit": "提交",
         "reset": "重置",
         "cancel": "取消",
-        "duplicated_pin_name": "应用错误: 输出了相同name的pin widget '%1'",
+        "duplicated_pin_name": "该 Pin widget 已失效(由于输出了新的同名 pin widget)",
     },
 };
 

+ 2 - 2
webiojs/src/models/pin.ts

@@ -54,8 +54,8 @@ export let PinWidget = {
     get_element: function (spec: any) {
         let input_spec = spec.input;
         if(input_spec.name in name2input){
-            error_alert(t("duplicated_pin_name", input_spec.name));
-            throw new Error(`Duplicated pin widget name: ${input_spec.name}`);
+            let tip = `<p style="color: grey; border:1px solid #ced4da; padding: .375rem .75rem;">${t("duplicated_pin_name")}</p>`;
+            name2input[input_spec.name].element.replaceWith(tip);
         }
 
         input_spec.onchange = true;