Skip to content

Instantly share code, notes, and snippets.

@pphetra
Created August 11, 2012 02:50
Show Gist options
  • Select an option

  • Save pphetra/3320209 to your computer and use it in GitHub Desktop.

Select an option

Save pphetra/3320209 to your computer and use it in GitHub Desktop.
form
<html>
<head>
<link rel="stylesheet" href="www/extjs/resources/css/ext-all.css">
<script src="www/extjs/ext-all-debug.js"></script>
<script>
Ext.onReady(function() {
Ext.apply(Ext.form.field.VTypes, {
nid: function(val, field) {
return /^\d{13}$/.test(val);
},
nidText: 'ไม่ใช่เลขบัตรประชาชน',
nidMask: /\d/
});
f1 = Ext.create('Ext.form.Panel', {
renderTo: document.body,
title: 'Employee Form',
height: 500,
width: 500,
bodyPadding: 10,
defaultType: 'textfield',
items: [
{
fieldLabel: 'เลขที่บัตรประชาชน',
name: 'nid',
vtype: 'nid',
allowBlank: false
},
{
fieldLabel: 'ชื่อ',
name: 'name',
allowBlank: false
},
{
fieldLabel: 'ที่อยู่',
xtype: 'textarea',
name: 'address',
allowBlank: false
},
{
xtype: 'datefield',
fieldLabel: 'วันที่สมัคร',
name: 'regisDate',
allowBlank: false,
format: 'd/m/y'
},
{
xtype: 'checkbox',
fieldLabel: 'ต้องการรับข่าวสาร',
name: 'mailSubscribe'
},
{
xtype: 'numberfield',
fieldLabel: 'อายุ',
name: 'age',
allowBlank: false,
maxValue: 70,
minValue: 8
}
],
buttons: [
{
text: 'Submit',
formBind: true,
handler: function() {
this.up('form').submit({
url: '/employees',
success: function(form, action) {
console.log(action.result);
Ext.Msg.alert('Success', 'เราได้รับข้อมูลท่านแล้ว้');
form.reset();
},
failure: function(form, action) {
Ext.Msg.alert('Error', 'ไม่สามารถ submit ข้อมูลได้');
}
})
}
},
{
text: 'Load',
handler: function() {
f1.load({ url: '/employee' , params: {id: 77}});
}
},
{
text: 'clear',
handler: function() {
this.up('form').getForm().reset();
}
}
]
})
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment