zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
    @name Edo.controls.Error
    @class
    @typeName error
    @description 错误显示条
    @extend Edo.controls.Control
*/
Edo.controls.Error = function(){
    Edo.controls.Error.superclass.constructor.call(this);    
    
};
Edo.controls.Error.extend(Edo.controls.Control,{
    /**
        @name Edo.controls.Error#text
        @property
        @type String
        @description 错误描述文本
    */
    text: '',
    /**
        @name Edo.controls.Error#autoWidth
        @property
        @default true
    */
    autoWidth: true,
    /**
        @name Edo.controls.Error#autoHeight
        @property
        @default true
    */
    autoHeight: true,
    elCls: 'e-error e-div',    
    minHeight: 16,
    /**
        @name Edo.controls.Error#visible
        @property
        @default false
    */
    visible: false,
    getInnerHtml: function(sb){
        sb[sb.length] = '<div class="e-error-inner">'+this.text+'</div><a class="e-error-close"></a>';
    },
    init: function(){
        Edo.controls.Error.superclass.init.call(this);
        
        this.on('click', function(e){
            if(Edo.util.Dom.hasClass(e.target, 'e-error-close')){
                this._onValid();
                var target = Edo.get(this.forId);
                if(!target) return;
                target.focus();
            }
        }, this);
    },
    _setText: function(value){
        if(this.text !== value){
            this.text = value;
            if(this.el){
                this.el.firstChild.innerHTML = value;
                //this.el.style.width = 'auto';
            }
            if(!Edo.isInt(this.width)){
                this.widthGeted = false;                
//                this.el.style.width = 'auto';
//                Edo.util.Dom.repaint(this.el);
            }
            if(!Edo.isInt(this.height)){
                this.heightGeted = false;
            }
            this.changeProperty('text', value);
            this.relayout('text', value);
        }
    },
    bind: function(forId){
        this.unbind(forId);
        var target = Edo.get(forId);
        if(!target) return;
        target.on('valid', this._onValid, this);
        target.on('invalid', this._onInValid, this);
    },
    unbind: function(forId){
        var target = Edo.get(forId);
        if(!target) return;
        target.un('valid', this._onValid, this);
        target.un('invalid', this._onInValid, this);
    },
    _onValid: function(e){    
        this.set('visible', false);
        this.set('text', '');
    },
    _onInValid: function(e){            
        this.set('text', e.errorMsg);
        this.set('visible', true);
    }
});
 
Edo.controls.Error.regType('error');