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.DisplayText = function(config){
20     Roo.form.DisplayText.superclass.constructor.call(this, config);
21     
22 };
23
24 Roo.extend(Roo.form.DisplayText, 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         Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
78         //if(this.inputValue !== undefined){
79         
80         
81         this.wrap = this.el.wrap();
82         this.viewEl = this.wrap.createChild({ tag: 'div'});
83         
84         if (this.bodyStyle) {
85             this.viewEl.applyStyles(this.bodyStyle);
86         }
87         //this.viewEl.setStyle('padding', '2px');
88         
89         this.setValue(this.value);
90         
91     },
92 /*
93     // private
94     initValue : Roo.emptyFn,
95
96   */
97
98         // private
99     onClick : function(){
100         
101     },
102
103     /**
104      * Sets the checked state of the checkbox.
105      * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
106      */
107     setValue : function(v){
108         this.value = v;
109         var html = this.valueRenderer ?  this.valueRenderer(v) : String.format('{0}', v);
110         this.viewEl.dom.innerHTML = html;
111         Roo.form.DisplayField.superclass.setValue.call(this, v);
112
113     }
114 });