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