roojs-ui.js
[roojs1] / Roo / form / DisplayField.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11 /**
12  * @class Roo.form.DisplayField
13  * @extends Roo.form.Field
14  * A generic Field to display non-editable data.
15  * @constructor
16  * Creates a new Display Field item.
17  * @param {Object} config Configuration options
18  */
19 Roo.form.DisplayField = function(config){
20     Roo.form.DisplayField.superclass.constructor.call(this, config);
21     
22 };
23
24 Roo.extend(Roo.form.DisplayField, Roo.form.TextField,  {
25     inputType:      'hidden',
26     allowBlank:     true,
27     readOnly:         true,
28     
29  
30     /**
31      * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
32      */
33     focusClass : undefined,
34     /**
35      * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
36      */
37     fieldClass: 'x-form-field',
38     
39      /**
40      * @cfg {Function} valueRenderer The renderer for the field (so you can reformat output). should return raw HTML
41      */
42     valueRenderer: undefined,
43     
44     width: 100,
45     /**
46      * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
47      * {tag: "input", type: "checkbox", autocomplete: "off"})
48      */
49      
50  //   defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
51
52     onResize : function(){
53         Roo.form.DisplayField.superclass.onResize.apply(this, arguments);
54         
55     },
56
57     initEvents : function(){
58         // Roo.form.Checkbox.superclass.initEvents.call(this);
59         // has no events...
60        
61     },
62
63
64     getResizeEl : function(){
65         return this.wrap;
66     },
67
68     getPositionEl : function(){
69         return this.wrap;
70     },
71
72     // private
73     onRender : function(ct, position){
74         
75         Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
76         //if(this.inputValue !== undefined){
77         this.wrap = this.el.wrap();
78         
79         this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
80         
81         if (this.bodyStyle) {
82             this.viewEl.applyStyles(this.bodyStyle);
83         }
84         //this.viewEl.setStyle('padding', '2px');
85         
86         this.setValue(this.value);
87         
88     },
89 /*
90     // private
91     initValue : Roo.emptyFn,
92
93   */
94
95         // private
96     onClick : function(){
97         
98     },
99
100     /**
101      * Sets the checked state of the checkbox.
102      * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
103      */
104     setValue : function(v){
105         this.value = v;
106         var html = this.valueRenderer ?  this.valueRenderer(v) : String.format('{0}', v);
107         // this might be called before we have a dom element..
108         if (!this.viewEl) {
109             return;
110         }
111         this.viewEl.dom.innerHTML = html;
112         Roo.form.DisplayField.superclass.setValue.call(this, v);
113
114     }
115 });