ffzhuang
13 Jun 2007, 7:17 PM
Hello,
I am using form function and submit the form information to the server-side. Server-side code get all the information. For example, create new Account action, if anything wrong, an error JSON message is created and through back to form. Form display the error message. If it is ok, nothing happen. My code look like this:
aAddAccBtn.on('click', function() {
if (!aAddAccDlg) {
aAddAccDlg = new Ext.LayoutDialog("a-addAcc-dlg", {
modal:true,
autoTabs:true,
proxyDrag:true,
resizable:false,
width: 480,
height: 302,
shadow:true,
center: {
autoScroll: true,
tabPosition: 'top',
closeOnTab: true,
alwaysShowTabs: false
}
});
aAddAccDlg.addKeyListener(27, aAddAccDlg.hide, aAddAccDlg);
aAddAccDlg.addButton('Reset', resetForm, aAddAccDlg);
aAddAccDlg.addButton('Save', function() {
// validation now
if (password_tf.getValue()!=cPassword_tf.getValue()) {
password_tf.markInvalid("passwords not match");
password_tf.focus();
return;
}
// submit now... all the form information are submit to the server
if (form_acc.isValid()) {
form_acc.submit({
waitMsg:'Creating new account now...'
});
// need catch server-side information, if error, keep currently dialog and display error message
// if success, make currently dialog disappear
aAddAccDlg.hide();
}else{
Ext.MessageBox.alert('Errors', 'Please fix the errors noted.');
}
});
aAddAccDlg.addButton('Cancel', function() {aAddAccDlg.hide();});
var layout = aAddAccDlg.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('a-addAcc-inner', {title: 'create account'}));
layout.endUpdate();
}
aAddAccDlg.show(aAddAccBtn.dom);
});
var lastname_tf = new Ext.form.TextField({
fieldLabel: 'Last Name',
name: 'lastname'
});
// create a new form now...
var form_acc = new Ext.form.Form({
labelAlign: 'right',
url:'/yuiExt/listAccount.do?action=createAccount'
});
form_acc.column({width: 430, labelWidth:120, style:'margin-left:8px;margin-top:8px'});
form_acc.fieldset(
{id:'desc', legend:'Please fill the field'},
username_tf,
password_tf,
cPassword_tf,
firstname_tf,
lastname_tf
);
form_acc.applyIfToFields({width:255});
form_acc.render('a-addAcc-form');
form_acc.end();
My problem is that how can I catch server-side error or success information. I do believe there exist a simple way to figure this out. The main reason I want to know success or fail is that:
If it is failed, I want to keep currently dialog. Do not run: aAddAccDlg.hide();
If it is success, I want to make current dialog disappear and run: aAddAccDlg.hide();
How can I easy know server-side validation status (flag to show success or fail). Does there exist any parameter (quick way) to know validation failed? For example, such error is created on server-side:
{errors:[(id:username, msg: username already used)]}.
Any suggestion would be great appreciate.
Thanks in advanced for your kind assistance
Regards!
Fenqiang Zhuang
I am using form function and submit the form information to the server-side. Server-side code get all the information. For example, create new Account action, if anything wrong, an error JSON message is created and through back to form. Form display the error message. If it is ok, nothing happen. My code look like this:
aAddAccBtn.on('click', function() {
if (!aAddAccDlg) {
aAddAccDlg = new Ext.LayoutDialog("a-addAcc-dlg", {
modal:true,
autoTabs:true,
proxyDrag:true,
resizable:false,
width: 480,
height: 302,
shadow:true,
center: {
autoScroll: true,
tabPosition: 'top',
closeOnTab: true,
alwaysShowTabs: false
}
});
aAddAccDlg.addKeyListener(27, aAddAccDlg.hide, aAddAccDlg);
aAddAccDlg.addButton('Reset', resetForm, aAddAccDlg);
aAddAccDlg.addButton('Save', function() {
// validation now
if (password_tf.getValue()!=cPassword_tf.getValue()) {
password_tf.markInvalid("passwords not match");
password_tf.focus();
return;
}
// submit now... all the form information are submit to the server
if (form_acc.isValid()) {
form_acc.submit({
waitMsg:'Creating new account now...'
});
// need catch server-side information, if error, keep currently dialog and display error message
// if success, make currently dialog disappear
aAddAccDlg.hide();
}else{
Ext.MessageBox.alert('Errors', 'Please fix the errors noted.');
}
});
aAddAccDlg.addButton('Cancel', function() {aAddAccDlg.hide();});
var layout = aAddAccDlg.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('a-addAcc-inner', {title: 'create account'}));
layout.endUpdate();
}
aAddAccDlg.show(aAddAccBtn.dom);
});
var lastname_tf = new Ext.form.TextField({
fieldLabel: 'Last Name',
name: 'lastname'
});
// create a new form now...
var form_acc = new Ext.form.Form({
labelAlign: 'right',
url:'/yuiExt/listAccount.do?action=createAccount'
});
form_acc.column({width: 430, labelWidth:120, style:'margin-left:8px;margin-top:8px'});
form_acc.fieldset(
{id:'desc', legend:'Please fill the field'},
username_tf,
password_tf,
cPassword_tf,
firstname_tf,
lastname_tf
);
form_acc.applyIfToFields({width:255});
form_acc.render('a-addAcc-form');
form_acc.end();
My problem is that how can I catch server-side error or success information. I do believe there exist a simple way to figure this out. The main reason I want to know success or fail is that:
If it is failed, I want to keep currently dialog. Do not run: aAddAccDlg.hide();
If it is success, I want to make current dialog disappear and run: aAddAccDlg.hide();
How can I easy know server-side validation status (flag to show success or fail). Does there exist any parameter (quick way) to know validation failed? For example, such error is created on server-side:
{errors:[(id:username, msg: username already used)]}.
Any suggestion would be great appreciate.
Thanks in advanced for your kind assistance
Regards!
Fenqiang Zhuang