Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / form / field / Hidden.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * A basic hidden field for storing hidden values in forms that need to be passed in the form submit.
17  *
18  * This creates an actual input element with type="submit" in the DOM. While its label is
19  * {@link #hideLabel not rendered} by default, it is still a real component and may be sized according
20  * to its owner container's layout.
21  *
22  * Because of this, in most cases it is more convenient and less problematic to simply
23  * {@link Ext.form.action.Action#params pass hidden parameters} directly when
24  * {@link Ext.form.Basic#submit submitting the form}.
25  *
26  * Example:
27  *
28  *     new Ext.form.Panel({
29  *         title: 'My Form',
30  *         items: [{
31  *             xtype: 'textfield',
32  *             fieldLabel: 'Text Field',
33  *             name: 'text_field',
34  *             value: 'value from text field'
35  *         }, {
36  *             xtype: 'hiddenfield',
37  *             name: 'hidden_field_1',
38  *             value: 'value from hidden field'
39  *         }],
40  *
41  *         buttons: [{
42  *             text: 'Submit',
43  *             handler: function() {
44  *                 this.up('form').getForm().submit({
45  *                     params: {
46  *                         hidden_field_2: 'value from submit call'
47  *                     }
48  *                 });
49  *             }
50  *         }]
51  *     });
52  *
53  * Submitting the above form will result in three values sent to the server:
54  *
55  *     text_field=value+from+text+field&hidden;_field_1=value+from+hidden+field&hidden_field_2=value+from+submit+call
56  *
57  */
58 Ext.define('Ext.form.field.Hidden', {
59     extend:'Ext.form.field.Base',
60     alias: ['widget.hiddenfield', 'widget.hidden'],
61     alternateClassName: 'Ext.form.Hidden',
62
63     // private
64     inputType : 'hidden',
65     hideLabel: true,
66     
67     initComponent: function(){
68         this.formItemCls += '-hidden';
69         this.callParent();    
70     },
71     
72     /**
73      * @private
74      * Override. Treat undefined and null values as equal to an empty string value.
75      */
76     isEqual: function(value1, value2) {
77         return this.isEqualAsString(value1, value2);
78     },
79
80     // These are all private overrides
81     initEvents: Ext.emptyFn,
82     setSize : Ext.emptyFn,
83     setWidth : Ext.emptyFn,
84     setHeight : Ext.emptyFn,
85     setPosition : Ext.emptyFn,
86     setPagePosition : Ext.emptyFn,
87     markInvalid : Ext.emptyFn,
88     clearInvalid : Ext.emptyFn
89 });
90