Skip to content
Snippets Groups Projects
Commit 7a8f0d50 authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

Add a method isFormValid.

Same message for all errors on forms.
parent 57683faa
No related branches found
No related tags found
No related merge requests found
...@@ -117,9 +117,7 @@ App.grid.RowEditor = Ext.extend(Ext.Window, { ...@@ -117,9 +117,7 @@ App.grid.RowEditor = Ext.extend(Ext.Window, {
var i, rec, record; var i, rec, record;
// Returns true if client-side validation on the form is successful. if (!this.isFormValid()) {
if (!this.formPanel.getForm().isValid()) {
Ext.Msg.alert('Error', 'Few fields in the form are not valid !');
return; return;
} }
...@@ -147,9 +145,7 @@ App.grid.RowEditor = Ext.extend(Ext.Window, { ...@@ -147,9 +145,7 @@ App.grid.RowEditor = Ext.extend(Ext.Window, {
var record; var record;
// Returns true if client-side validation on the form is successful. if (!this.isFormValid()) {
if (!this.formPanel.getForm().isValid()) {
Ext.Msg.alert('Error', 'Few fields in the form are not valid !');
return; return;
} }
...@@ -179,6 +175,36 @@ App.grid.RowEditor = Ext.extend(Ext.Window, { ...@@ -179,6 +175,36 @@ App.grid.RowEditor = Ext.extend(Ext.Window, {
this.hide(); this.hide();
}, },
/**
* Private function checking that a form is valid.
* This is the case when all underlying fields satisfied validator criteria.
* Return a boolean and show a popup window in case of errors.
*/
isFormValid: function () {
var form, msg;
function fieldsInError(form) {
var badFields = [];
form.items.each(function(field){
if (!field.validate()) {
badFields.push(field.fieldLabel);
}
});
return badFields;
}
form = this.formPanel.getForm();
if (!form.isValid()) {
badFields = fieldsInError(form);
msg = 'Missing or invalid fields: ';
msg += badFields.join(', ');
Ext.Msg.alert('Failure', msg);
return false;
}
return true;
},
/** /**
* Private method to return the record * Private method to return the record
* associate to the row selected in the grid * associate to the row selected in the grid
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment