فهرست منبع

combobox clearable属性在readOnly设置时的控制

zhuth 6 سال پیش
والد
کامیت
131e9e9f87
2فایلهای تغییر یافته به همراه54 افزوده شده و 4 حذف شده
  1. 1 1
      frontend/pc-web/app/view/basic/student/StudentDetail.js
  2. 53 3
      frontend/pc-web/overrides/form/field/ComboBox.js

+ 1 - 1
frontend/pc-web/app/view/basic/student/StudentDetail.js

@@ -64,7 +64,7 @@ Ext.define('school.view.basic.student.StudentDetail', {
                 fieldLabel: '政治面貌',
                 displayField: 'name',
                 valueField: 'name',
-                editable: false,
+                editable: true,
                 store: Ext.create('Ext.data.ArrayStore', {
                     fields: ['name'],
                     data: [

+ 53 - 3
frontend/pc-web/overrides/form/field/ComboBox.js

@@ -9,18 +9,21 @@ Ext.define("school.override.form.field.ComboBox", {
                 weight: -1,
                 cls: 'fa-times',
                 hidden: true,
+                lazyVisible: true,
                 onFieldFocus: function() {
-                    if(this.field.clearable) {
+                    var field = this.field;
+                    if(!field.readOnly && field.clearable) {
                         this.setHidden(false);
                     }
                 },
                 onFieldBlur: function() {
-                    if(this.field.clearable) {
+                    var field = this.field;
+                    if(!field.readOnly && field.clearable) {
                         this.setHidden(true);
                     }
                 },
                 handler: function() {
-                    if(this.clearable) {
+                    if(!this.readOnly && this.clearable) {
                         this.setValue(null)
                         this.triggers.clear.setHidden(true)
                         this.fireEvent('clear', this);
@@ -35,4 +38,51 @@ Ext.define("school.override.form.field.ComboBox", {
         }
     },
 
+    setReadOnly: function(readOnly) {
+        var me = this,
+            triggers = me.getTriggers(),
+            hideTriggers = me.getHideTrigger(),
+            oVisible = {},
+            trigger,
+            id;
+ 
+        readOnly = !!readOnly;
+ 
+        if (triggers) {
+            for (id in triggers) {
+                oVisible[id] = triggers[id].isVisible();
+            }
+        }
+
+        me.callParent([readOnly]);
+        if (me.rendered) {
+            me.setReadOnlyAttr(readOnly || !me.editable);
+        }
+ 
+        if (triggers) {
+            for (id in triggers) {
+                trigger = triggers[id];
+
+                /**
+                 * if trigger's 'lazyVisible' is true,this trigger's 'visible' will not controlled beed 'setReadOnly'
+                 */
+                if(trigger.lazyVisible) {
+                    trigger.setVisible(oVisible[id]);
+                    continue;
+                }
+
+                /*
+                 * Controlled trigger visibility state is only managed fully when 'hideOnReadOnly' is falsy.
+                 * Truth table:
+                 *   - If the trigger is configured/defaulted as 'hideOnReadOnly : true', it's readOnly-visibility
+                 *     is determined solely by readOnly state of the Field.
+                 *   - If 'hideOnReadOnly : false/undefined', the Fields.{link #hideTrigger hideTrigger} is honored.
+                 */
+                if (trigger.hideOnReadOnly === true || (trigger.hideOnReadOnly !== false && !hideTriggers)) {
+                    trigger.setVisible(!readOnly);
+                }
+            }
+        }
+    },
+
 });