Ext form实例

添加评论 100 views 2009年12月8日

Ext.BLANK_IMAGE_URL = “../js/extjs/resources/images/default/s.gif”;
Ext.onReady(form11);
function form1() {
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = “side”;
var form = new Ext.form.FormPanel({
title : “用户登陆”,
labelWidth : 60,
labelSeparator : “: “,
bodyStyle : “padding:15 5 5 5″,
height : 120,
width : 250,
frame : true,
labelWidth : 60,
labelAlign : “right”,
applyTo : “form”,

?View Code JAVASCRIPT
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
	items : [new Ext.form.TextField({
			fieldLabel : "用户名",
			id : "userName",
			minLength : 6,
			minLengthText : "长度不能小于6个字符",
			maxLength : 20,
			maxLengthText : "长度超过了20个字符",
			selectOnFocus : true,
			allowBlank : false,
			blankText : "请填写用户名",
			regex : /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/,
			regexText : "用户名格式错误"
		}), new Ext.form.TextField({
			inputType : "password",
			fieldLabel : "密码",
			allowBlank : false,
			blankText : "请填写密码",
			minLength : 6,
			minLengthText : "长度不能小于6个字符",
			maxLength : 20,
			maxLengthText : "长度超过了20个字符"
		})]
	})
}
function form2() {
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = "tip";
	var form = new Ext.form.FormPanel({
		title : "多行文本",
		labelWidth : 60,
		labelSeparator : ": ",
		bodyStyle : "padding:15 5 5 5",
		height : 250,
		width : 250,
		frame : true,
		labelWidth : 60,
		labelAlign : "right",
		applyTo : "form",
		items : [new Ext.form.TextArea({
			fieldLabel : "备注",
			id : "memo",
			width : 150
		}), new Ext.form.Radio({
			name : "sex",
			fieldLabel : "性别",
			boxLabel : "男"
 
		}), new Ext.form.Radio({
			name : "sex",
			fieldLabel : "性别",
			boxLabel : "女"
 
		}), new Ext.form.Checkbox({
			name : "walk",
			fieldLabel : "爱好",
			boxLabel : "散步"
		})],
		buttons : [{
			text : "确定",
			handler : showValue
		}]
	})
	function showValue() {
		var memo = form.findById("memo");
		alert(memo.getValue());
	}
}
 
function form3() {
	var form = new Ext.form.FormPanel({
		title : "练习Trigger",
		labelSeparator : ": ",
		labelWidth : 80,
		bodyStyle : "padding:5 5 5 5",
		frame : true,
		height : 100,
		width : 270,
		applyTo : "form",
		items : [new Ext.form.TriggerField({
			id : "memo",
			fieldLabel : "触发字段",
			hideTrigger : false,
			onTriggerClick : function(e) {
				var memo = form.findById("memo");
				alert(memo.getValue());
			}
		})]
	})
}
 
function form4() {
	var store = new Ext.data.SimpleStore({
		fields : ["province", "post"],
		data : [["南充", "0"], ["成都", "1"], ["广元", "2"], ["乐山", "3"]]
	});
	var form = new Ext.form.FormPanel({
		title : "练习Trigger",
		labelSeparator : ": ",
		labelWidth : 80,
		bodyStyle : "padding:5 5 5 5",
		frame : true,
		height : 100,
		width : 340,
		applyTo : "form",
		items : [new Ext.form.ComboBox({
			id : "post",
			fieldLabel : "四川的城市",
			triggerAction : "all",
			store : store,
			displayField : "province",
			valueField : "post",
			mode : "local",
			forceSelection : true,
			resization : true,
			typeAhead : true,
			value : "3",
			handleHeight : 100
		})]
 
	})
}
 
function form5() {
	var store = new Ext.data.SimpleStore({
		proxy : new Ext.data.HttpProxy({
			url : "/learn/index.jsp"
		}),
		fields : ["bookName"]
	});
	var form = new Ext.form.FormPanel({
		title : "远程数据",
		labelSeparator : ": ",
		labelWidth : 80,
		bodyStyle : "padding:5 5 5 5",
		frame : true,
		height : 100,
		width : 300,
		applyTo : "form",
		items : [new Ext.form.ComboBox({
			id : "book",
			allQuery : "allbook",
			loadingText : "正在加载数据",
			minChars : 3,
			queyDelay : 300,
			queryParam : "searchbook",
			fieldLabel : "书籍列表",
			triggerAction : "all",
			store : store,
			displayField : "bookName",
			mode : "remote"
		})]
	})
}
 
function form6() {
	Ext.apply(Ext.form.VTypes, {
		dateRange : function(val, field) {
			if (field.dateRange) {
				var beginId = field.dateRange.begin;
				/** 根据组件id得到组件 */
				this.beginField = Ext.getCmp(beginId);
				var endId = field.dateRange.end;
				this.endField = Ext.getCmp(endId);
				var beginDate = this.beginField.getValue();
				var endDate = this.endField.getValue();
			}
			if (beginDate < = endDate) {
				return true;
			} else {
				return false;
			}
		},
		dateRangeText : "开始日期不能大于结束日期"
	});
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = "side";
	var dateForm = new Ext.form.FormPanel({
		title : "自定义form",
		labelSeparator : ":",
		labelWidth : 80,
		bodyStyle : "padding:5 5 5 5",
		frame : true,
		height : 130,
		width : 300,
		applyTo : "form",
		items : [new Ext.form.DateField({
			id : "beginDate",
			format : "Y年m月d日",
			width : 150,
			allowBlank : false,
			readOnly : true,
			value : new Date(),
			fieldLabel : "开始日期",
			dateRange : {
				begin : "beginDate",
				end : "endDate"
			},
			vtype : "dateRange"
		}), new Ext.form.DateField({
			id : "endDate",
			format : "Y年m月d日",
			width : 150,
			allowBlank : false,
			readOnly : true,
			value : new Date(),
			fieldLabel : "开始日期",
			dateRange : {
				begin : "beginDate",
				end : "endDate"
			},
			vtype : "dateRange"
		})],
		buttons : [new Ext.Button({
			text : "提交",
			handler : function() {
				if (dateForm.form.isValid()) {
					Ext.Msg.alert("提示", "验证通过提交表单");
				}
			}
		})]
	})
}
 
function form7() {
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = "side";
	var productForm = new Ext.form.FormPanel({
		title : "表单加载示例",
		labelWidth : 100,
		width : 300,
		frame : true,
		labelSeparator : ": ",
		applyTo : "form",
		items : [new Ext.form.TextField({
			fieldLabel : "产品名称",
			name : "productName",
			width : 150,
			value : "HP5720本本"
		}), new Ext.form.NumberField({
			fieldLabel : "金额",
			name : "price",
			width : 150,
			value : 100
		}), new Ext.form.DateField({
			fieldLabel : "生产日期",
			formate : "Y年m月d日",
			width : 150,
			name : "date",
			value : new Date()
		}), new Ext.form.TextArea({
			id : "introduction",
			name : "introduction",
			fieldLabel : "产品简介",
			width : 150
		})],
		buttons : [new Ext.Button({
			text : "加载简介",
			handler : loadCallBack
		})]
	});
	function loadCallBack() {
		productForm.form.load({
			waitMsg : "正在加载产品简介信息",
			waitTitle : "提示",
			url : "/learn/productServe.jsp",
			method : "POST",
			success : function(form, action) {
				Ext.Msg.alert("提示", "产品加载成功");
			},
			failure : function(form, action) {
				Ext.Msg.alert("提示", "产品简介加载失败
失败原因:" + action.failureType);
			}
		});
	}
}
 
function form8() {
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = "side";
	var loginForm = new Ext.form.FormPanel({
		title : "登陆",
		labelWidth : 60,
		width : 230,
		frame : true,
		labelSeparator : ":",
		applyTo : "form",
		items : [new Ext.form.TextField({
			fieldLabel : "用户名",
			name : "userName",
			allowBlank : false,
			vtype : "email"
		}), new Ext.form.NumberField({
			fieldLabel : "密码",
			name : "password",
			allowBlank : false
		})],
		buttons : [new Ext.Button({
			text : "登陆",
			handler : login
		}), new Ext.Button({
			text : "重置",
			handler : reset
		})]
	});
	function login() {
		loginForm.form.submit({
			clientValidation : true,
			waitMsg : "正在登录系统请稍后",
			waitTitle : "提示",
			url : "/learn/loginServe.jsp",
			method : "GET",
			success : function(form, action) {
				Ext.Msg.alert("提示", "系统登录成功");
			},
			failure : function(form, action) {
				Ext.Msg.alert("提示", "系统登陆失败" + action.failureType);
			}
		});
	}
	function reset() {
		loginForm.form.reset();
	}
}
 
function form9() {
	var form = new Ext.form.FormPanel({
		labelAlign : 'right',
		labelWidth : 50,
		width : 600,
		title : 'form',
		frame : true,
		items : [{
			layout : 'column',
			items : [{
				columnWidth : .7,
				xtype : 'fieldset',
				checkboxToggle : true,
				title : '单纯输入',
				autoHeight : true,
				defaults : {
					width : 300
				},
				defaultType : 'textfield',
				items : [{
					fieldLabel : '文本',
					name : 'text'
				}, {
					xtype : 'numberfield',
					fieldLabel : '数字',
					name : 'number'
				}, {
					xtype : "combo",
					fieldLabel : '选择',
					name : 'combo',
					store : new Ext.data.SimpleStore({
						fields : ['value', 'text'],
						data : [['value1', 'text1'], ['value2', 'text2']]
					}),
					displayField : 'text',
					valueField : 'value',
					mode : 'local',
					emptyText : '请选择'
				}, {
					xtype : 'datefield',
					fieldLabel : '日期',
					name : 'date'
				}, {
					xtype : 'timefield',
					fieldLabel : '时间',
					name : 'time'
				}, {
					xtype : 'textarea',
					fieldLabel : '多行',
					name : 'textarea'
				}, {
					xtype : 'hidden',
					name : 'hidden'
				}]
			}, {
				columnWidth : .3,
				layout : 'form',
				items : [{
					xtype : 'fieldset',
					checkboxToggle : true,
					title : '多选',
					autoHeight : true,
					defaultType : 'checkbox',
					hideLabels : true,
					style : 'margin-left:10px;',
					bodyStyle : 'margin-left:20px;',
					items : [{
						boxLabel : '首先要穿暖',
						name : 'check',
						value : '1',
						checked : true,
						width : 'auto'
					}, {
						boxLabel : '然后要吃饱',
						name : 'check',
						value : '2',
						checked : true,
						width : 'auto'
					}, {
						boxLabel : '房子遮风避雨',
						name : 'check',
						value : '3',
						width : 'auto'
					}, {
						boxLabel : '行路方便',
						name : 'check',
						value : '4',
						width : 'auto'
					}]
				}, {
					xtype : 'fieldset',
					checkboxToggle : true,
					title : '单选',
					autoHeight : true,
					defaultType : 'radio',
					hideLabels : true,
					style : 'margin-left:10px;',
					bodyStyle : 'margin-left:20px;',
					items : [{
						boxLabel : '渴望自由',
						name : 'rad',
						value : '1',
						checked : true,
						width : 'auto'
					}, {
						boxLabel : '祈求爱情',
						name : 'rad',
						value : '2',
						width : 'auto'
					}]
				}]
			}]
		}, {
			layout : 'form',
			labelAlign : 'top',
			items : [{
				xtype : 'htmleditor',
				fieldLabel : '在线编辑器',
				id : 'editor',
				anchor : '98%'
			}]
		}],
		buttons : [{
			text : '保存'
		}, {
			text : '读取'
		}, {
			text : '取消'
		}]
	});
	form.render("form");
}
 
function form10() {
	var field1 = new Ext.form.Field({
		fieldLabel : 'qtip',
		msgTarget : 'qtip'
	});
	var field2 = new Ext.form.Field({
		fieldLabel : 'title',
		msgTarget : 'title'
	});
	var field3 = new Ext.form.Field({
		fieldLabel : 'side',
		msgTarget : 'side'
	});
	var field4 = new Ext.form.Field({
		fieldLabel : 'under',
		msgTarget : 'under'
	});
 
	var form = new Ext.form.FormPanel({
		title : 'form',
		frame : true,
		applyTo : "form",
		items : [field1, field2, field3, field4],
		renderTo : 'form'
	});
	field1.markInvalid();
	field2.markInvalid();
	field3.markInvalid();
	field4.markInvalid();
};
 
function form11() {
	var grid = new Ext.grid.GridPanel({
		width : 300,
		autoHeight : true,
		title : 'grid',
		store : new Ext.data.SimpleStore({
			data : [['name1', 'female', 'descn1'], ['name2', 'male', 'descn2'],
					['name2', 'male', 'descn2'], ['name2', 'male', 'descn2']],
			fields : ['name', 'sex', 'descn']
		}),
		columns : [{
			header : '姓名',
			dataIndex : 'name'
		}, {
			header : '性别',
			dataIndex : 'sex'
		}, {
			header : '备注',
			dataIndex : 'descn'
		}],
		viewConfig : {
			forceFit : true
		}
	});
 
	var selectMenu = new Ext.menu.Menu({
		items : [grid]
	});
 
	var field = new Ext.form.TriggerField({
		fieldLabel : '选择',
		name : 'name',
		onSelect : function(record) {
		},
		onTriggerClick : function() {
			if (this.menu == null) {
				this.menu = selectMenu;
			}
			this.menu.show(this.el, "tl-bl?");
		}
	});
 
	grid.on('rowclick', function(grid, rowIndex, e) {
		selectMenu.hide();
		field.setValue(rowIndex);
	});
 
	var form = new Ext.form.FormPanel({
		title : 'form',
		frame : true,
		items : [field],
		renderTo : 'form'
	});
}
  1. 还没有评论.想坐沙发?
  1. 还没有 trackbacks
订阅评论