Roo/form/DisplayField.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 Ext.form.DisplayField
13  * @extends Ext.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 Ext.form.DisplayText = function(config){
20     Ext.form.DisplayText.superclass.constructor.call(this, config);
21     
22 };
23
24 Ext.extend(Ext.form.DisplayText, Ext.form.Field,  {
25     /**
26      * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
27      */
28     focusClass : undefined,
29     /**
30      * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
31      */
32     fieldClass: 'x-form-field',
33     
34      /**
35      * @cfg {Function} renderer The renderer for the field (so you can reformat output). should return raw HTML
36      */
37     renderer: undefined,
38     
39     /**
40      * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
41      * {tag: "input", type: "checkbox", autocomplete: "off"})
42      */
43      
44     defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
45
46     onResize : function(){
47         Ext.form.Field.superclass.onResize.apply(this, arguments);
48         
49     },
50
51     initEvents : function(){
52         // Ext.form.Checkbox.superclass.initEvents.call(this);
53         // has no events...
54        
55     },
56
57
58     getResizeEl : function(){
59         return this.wrap;
60     },
61
62     getPositionEl : function(){
63         return this.wrap;
64     },
65
66     // private
67     onRender : function(ct, position){
68         Ext.form.DisplayText.superclass.onRender.call(this, ct, position);
69         //if(this.inputValue !== undefined){
70         
71         
72         this.wrap = this.el.wrap();
73         this.viewEl = this.wrap.createChild({ tag: 'div'});
74         
75         if (this.bodyStyle) {
76             this.viewEl.applyStyles(this.bodyStyle);
77         }
78         //this.viewEl.setStyle('padding', '2px');
79         
80         this.setValue(this.value);
81         
82     },
83
84     // private
85     initValue : Ext.emptyFn,
86
87   
88
89         // private
90     onClick : function(){
91         
92     },
93
94     /**
95      * Sets the checked state of the checkbox.
96      * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
97      */
98     setValue : function(v){
99         this.value = v;
100         var html = this.renderer ?  this.renderer(v) : String.format('{0}', v);
101         this.viewEl.dom.innerHTML = html;
102         Roo.form.DisplayText.superclass.setValue.call(this, v);
103
104     }
105 });