check-radio.js
13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
Ext.require([
'Ext.form.*',
'Ext.layout.container.Column',
'Ext.window.MessageBox',
'Ext.fx.target.Element'
]);
Ext.onReady(function(){
/*====================================================================
* Individual checkbox/radio examples
*====================================================================*/
// Using checkbox/radio groups will generally be more convenient and flexible than
// using individual checkbox and radio controls, but this shows that you can
// certainly do so if you only have a single control at a time.
var individual = {
xtype: 'container',
layout: 'hbox',
margin: '0 0 10',
items: [{
xtype: 'fieldset',
flex: 1,
title: 'Individual Checkboxes',
defaultType: 'checkbox', // each item will be a checkbox
layout: 'anchor',
defaults: {
anchor: '100%',
hideEmptyLabel: false
},
items: [{
xtype: 'textfield',
name: 'txt-test1',
fieldLabel: 'Alignment Test'
}, {
fieldLabel: 'Favorite Animals',
boxLabel: 'Dog',
name: 'fav-animal-dog',
inputValue: 'dog'
}, {
boxLabel: 'Cat',
name: 'fav-animal-cat',
inputValue: 'cat'
}, {
checked: true,
boxLabel: 'Monkey',
name: 'fav-animal-monkey',
inputValue: 'monkey'
}]
}, {
xtype: 'component',
width: 10
}, {
xtype: 'fieldset',
flex: 1,
title: 'Individual Radios',
defaultType: 'radio', // each item will be a radio button
layout: 'anchor',
defaults: {
anchor: '100%',
hideEmptyLabel: false
},
items: [{
xtype: 'textfield',
name: 'txt-test2',
fieldLabel: 'Alignment Test'
}, {
checked: true,
fieldLabel: 'Favorite Color',
boxLabel: 'Red',
name: 'fav-color',
inputValue: 'red'
}, {
boxLabel: 'Blue',
name: 'fav-color',
inputValue: 'blue'
}, {
boxLabel: 'Green',
name: 'fav-color',
inputValue: 'green'
}]
}]
};
/*====================================================================
* CheckGroup example
*====================================================================*/
var checkGroup = {
xtype: 'fieldset',
title: 'Checkbox Groups (initially collapsed)',
layout: 'anchor',
defaults: {
anchor: '100%',
labelStyle: 'padding-left:4px;'
},
collapsible: true,
collapsed: true,
items: [{
xtype: 'textfield',
name: 'txt-test3',
fieldLabel: 'Alignment Test'
},{
// Use the default, automatic layout to distribute the controls evenly
// across a single row
xtype: 'checkboxgroup',
fieldLabel: 'Auto Layout',
cls: 'x-check-group-alt',
items: [
{boxLabel: 'Item 1', name: 'cb-auto-1'},
{boxLabel: 'Item 2', name: 'cb-auto-2', checked: true},
{boxLabel: 'Item 3', name: 'cb-auto-3'},
{boxLabel: 'Item 4', name: 'cb-auto-4'},
{boxLabel: 'Item 5', name: 'cb-auto-5'}
]
},{
xtype: 'checkboxgroup',
fieldLabel: 'Single Column',
// Put all controls in a single column with width 100%
columns: 1,
items: [
{boxLabel: 'Item 1', name: 'cb-col-1'},
{boxLabel: 'Item 2', name: 'cb-col-2', checked: true},
{boxLabel: 'Item 3', name: 'cb-col-3'}
]
},{
xtype: 'checkboxgroup',
fieldLabel: 'Multi-Column (horizontal)',
cls: 'x-check-group-alt',
// Distribute controls across 3 even columns, filling each row
// from left to right before starting the next row
columns: 3,
items: [
{boxLabel: 'Item 1', name: 'cb-horiz-1'},
{boxLabel: 'Item 2', name: 'cb-horiz-2', checked: true},
{boxLabel: 'Item 3', name: 'cb-horiz-3'},
{boxLabel: 'Item 4', name: 'cb-horiz-4'},
{boxLabel: 'Item 5', name: 'cb-horiz-5'}
]
},{
xtype: 'checkboxgroup',
fieldLabel: 'Multi-Column (vertical)',
// Distribute controls across 3 even columns, filling each column
// from top to bottom before starting the next column
columns: 3,
vertical: true,
items: [
{boxLabel: 'Item 1', name: 'cb-vert-1'},
{boxLabel: 'Item 2', name: 'cb-vert-2', checked: true},
{boxLabel: 'Item 3', name: 'cb-vert-3'},
{boxLabel: 'Item 4', name: 'cb-vert-4'},
{boxLabel: 'Item 5', name: 'cb-vert-5'}
]
},{
xtype: 'checkboxgroup',
fieldLabel: 'Multi-Column<br />(custom widths)',
cls: 'x-check-group-alt',
// Specify exact column widths (could also include float values for %)
columns: [100, 100],
vertical: true,
items: [
{boxLabel: 'Item 1', name: 'cb-custwidth', inputValue: 1},
{boxLabel: 'Item 2', name: 'cb-custwidth', inputValue: 2, checked: true},
{boxLabel: 'Item 3', name: 'cb-custwidth', inputValue: 3},
{boxLabel: 'Item 4', name: 'cb-custwidth', inputValue: 4},
{boxLabel: 'Item 5', name: 'cb-custwidth', inputValue: 5}
]
},{
xtype: 'checkboxgroup',
fieldLabel: 'Custom Layout<br />(w/ validation)',
allowBlank: false,
msgTarget: 'side',
autoFitErrors: false,
anchor: '-18',
// You can change the 'layout' to anything you want, and include any nested
// container structure, for complete layout control. In this example we only
// want one item in the middle column, which would not be possible using the
// default 'checkboxgroup' layout's columns config. We also want to put
// headings at the top of each column.
layout: 'column',
defaultType: 'container',
items: [{
columnWidth: .25,
items: [
{xtype: 'component', html: 'Heading 1', cls:'x-form-check-group-label'},
{xtype: 'checkboxfield', boxLabel: 'Item 1', name: 'cb-cust-1'},
{xtype: 'checkboxfield', boxLabel: 'Item 2', name: 'cb-cust-2'}
]
},{
columnWidth: .5,
items: [
{xtype: 'component', html: 'Heading 2', cls:'x-form-check-group-label'},
{xtype: 'checkboxfield', boxLabel: 'A long item just for fun', name: 'cb-cust-3'}
]
},{
columnWidth: .25,
items: [
{xtype: 'component', html: 'Heading 3', cls:'x-form-check-group-label'},
{xtype: 'checkboxfield', boxLabel: 'Item 4', name: 'cb-cust-4'},
{xtype: 'checkboxfield', boxLabel: 'Item 5', name: 'cb-cust-5'}
]
}]
}]
};
/*====================================================================
* RadioGroup examples
*====================================================================*/
// NOTE: These radio examples use the exact same options as the checkbox ones
// above, so the comments will not be repeated. Please see comments above for
// additional explanation on some config options.
var radioGroup = {
xtype: 'fieldset',
title: 'Radio Groups',
// in this section we use the form layout that will aggregate all of the fields
// into a single table, rather than one table per field.
layout: 'form',
defaults: {
labelStyle: 'padding-left:4px;'
},
collapsible: true,
items: [{
xtype: 'textfield',
name: 'txt-test4',
fieldLabel: 'Alignment Test'
},{
xtype: 'radiogroup',
fieldLabel: 'Auto Layout',
cls: 'x-check-group-alt',
items: [
{boxLabel: 'Item 1', name: 'rb-auto', inputValue: 1},
{boxLabel: 'Item 2', name: 'rb-auto', inputValue: 2, checked: true},
{boxLabel: 'Item 3', name: 'rb-auto', inputValue: 3},
{boxLabel: 'Item 4', name: 'rb-auto', inputValue: 4},
{boxLabel: 'Item 5', name: 'rb-auto', inputValue: 5}
]
},{
xtype: 'radiogroup',
fieldLabel: 'Single Column',
columns: 1,
items: [
{boxLabel: 'Item 1', name: 'rb-col', inputValue: 1},
{boxLabel: 'Item 2', name: 'rb-col', inputValue: 2, checked: true},
{boxLabel: 'Item 3', name: 'rb-col', inputValue: 3}
]
},{
xtype: 'radiogroup',
fieldLabel: 'Multi-Column (horizontal)',
cls: 'x-check-group-alt',
columns: 3,
items: [
{boxLabel: 'Item 1', name: 'rb-horiz-1', inputValue: 1},
{boxLabel: 'Item 2', name: 'rb-horiz-1', inputValue: 2, checked: true},
{boxLabel: 'Item 3', name: 'rb-horiz-1', inputValue: 3},
{boxLabel: 'Item 1', name: 'rb-horiz-2', inputValue: 1, checked: true},
{boxLabel: 'Item 2', name: 'rb-horiz-2', inputValue: 2}
]
},{
xtype: 'radiogroup',
fieldLabel: 'Multi-Column (vertical)',
columns: 3,
vertical: true,
items: [
{boxLabel: 'Item 1', name: 'rb-vert', inputValue: 1},
{boxLabel: 'Item 2', name: 'rb-vert', inputValue: 2, checked: true},
{boxLabel: 'Item 3', name: 'rb-vert', inputValue: 3},
{boxLabel: 'Item 4', name: 'rb-vert', inputValue: 4},
{boxLabel: 'Item 5', name: 'rb-vert', inputValue: 5}
]
},{
xtype: 'radiogroup',
fieldLabel: 'Multi-Column<br />(custom widths)',
cls: 'x-check-group-alt',
columns: [100, 100],
vertical: true,
items: [
{boxLabel: 'Item 1', name: 'rb-custwidth', inputValue: 1},
{boxLabel: 'Item 2', name: 'rb-custwidth', inputValue: 2, checked: true},
{boxLabel: 'Item 3', name: 'rb-custwidth', inputValue: 3},
{boxLabel: 'Item 4', name: 'rb-custwidth', inputValue: 4},
{boxLabel: 'Item 5', name: 'rb-custwidth', inputValue: 5}
]
},{
xtype: 'radiogroup',
fieldLabel: 'Custom Layout<br />(w/ validation)',
allowBlank: false,
msgTarget: 'side',
autoFitErrors: false,
anchor: '-18',
layout: 'column',
defaultType: 'container',
items: [{
columnWidth: .25,
items: [
{xtype: 'component', html: 'Heading 1', cls:'x-form-check-group-label'},
{xtype: 'radiofield', boxLabel: 'Item 1', name: 'rb-cust', inputValue: 1},
{xtype: 'radiofield', boxLabel: 'Item 2', name: 'rb-cust', inputValue: 2}
]
},{
columnWidth: .5,
items: [
{xtype: 'component', html: 'Heading 2', cls:'x-form-check-group-label'},
{xtype: 'radiofield', boxLabel: 'A long item just for fun', name: 'rb-cust', inputValue: 3}
]
},{
columnWidth: .25,
items: [
{xtype: 'component', html: 'Heading 3', cls:'x-form-check-group-label'},
{xtype: 'radiofield', boxLabel: 'Item 4', name: 'rb-cust', inputValue: 4},
{xtype: 'radiofield', boxLabel: 'Item 5', name: 'rb-cust', inputValue: 5}
]
}]
}]
};
// combine all that into one huge form
var fp = Ext.create('Ext.FormPanel', {
title: 'Check/Radio Groups Example',
frame: true,
fieldDefaults: {
labelWidth: 110
},
width: 600,
renderTo:'form-ct',
bodyPadding: 10,
items: [
individual,
checkGroup,
radioGroup
],
buttons: [{
text: 'Save',
handler: function(){
if(fp.getForm().isValid()){
Ext.Msg.alert('Submitted Values', 'The following will be sent to the server: <br />'+
fp.getForm().getValues(true).replace(/&/g,', '));
}
}
},{
text: 'Reset',
handler: function(){
fp.getForm().reset();
}
}]
});
});