2013년 10월 16일 수요일

Handling exception and callbacks

1. Start by creating a simple form panel:
var formPanel = Ext.create('Ext.form.Panel', {
title: 'Form',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
style: 'margin: 50px',
items: [],
buttons: []
});

2. Add a field to the form and set allowBlank to false:
var formPanel = Ext.create('Ext.form.Panel', {
...
items: [{
xtype: 'textfield',
fieldLabel: 'Text field',
name: 'field',
allowBlank: false
}],
buttons: []
});

3. Add a button to handle the forms submission and add success and failure
handlers to the submit method's only parameter:
var formPanel = Ext.create('Ext.form.Panel', {
...
buttons: [{
text: 'Submit',
handler: function(){
formPanel.getForm().submit({
url: 'submit.php',
success: function(form, action){
Ext.Msg.alert('Success', action.result.message);
},
failure: function(form, action){
if (action.failureType === Ext.form.action.Action.
CLIENT_INVALID) {
Ext.Msg.alert('CLIENT_INVALID', 'Something
has been missed. Please check and try again.');
}
if (action.failureType === Ext.form.action.Action.
CONNECT_FAILURE) {
Ext.Msg.alert('CONNECT_FAILURE', 'Status: ' +
action.response.status + ': ' + action.response.statusText);
}
if (action.failureType === Ext.form.action.Action.
SERVER_INVALID) {
Ext.Msg.alert('SERVER_INVALID', action.result.
message);
}
}
});
}
}]
});


댓글 없음:

댓글 쓰기