PDA

View Full Version : Static form !isValid but will submit



Jeroen Sen
5 Jun 2007, 2:10 PM
I'm a big fan of gracefull degradation. So, when on the client side javascript has been turned of, for whatever type of reason, my app still has to function. That's why I do not use a dynamic build form, but I used one that already has been created by the backend. This all works like a charm, exept when a form turns out to be invalid (!isValid) it still gets posted. Do one of you guys have an idea why this happens?

the code I'm using:


var UserNew = {

// convert the form fields that are build for the user
init : function(){

var aVaildation = [];

// enable the validation/error messages
Ext.QuickTips.init();

//Ext.form.Field.prototype.msgTarget = 'side';

// register the form
var form_UserNew = Ext.get('UserNew');

form_UserNew = new Ext.form.Form({
});

form_UserNew.add(

sLogin = new Ext.form.TextField({
width: 200,
allowBlank: false
}),
sLogin.applyTo('sLogin'),


sPass = new Ext.form.TextField({
width: 200,
allowBlank: false
}),
sPass.applyTo('sPass'),

sSurname = new Ext.form.TextField({
width: 200,
allowBlank: false
}),
sSurname.applyTo('sSurname'),

sInitials = new Ext.form.TextField({
width: 200
}),
sInitials.applyTo('sInitials'),

sFirstname = new Ext.form.TextField({
width: 200,
allowBlank: false
}),
sFirstname.applyTo('sFirstname'),

sEmail = new Ext.form.TextField({
width: 200,
allowBlank: false,
vtype: 'email'
}),
sEmail.applyTo('sEmail'),

sTelephone = new Ext.form.TextField({
width: 200
}),
sTelephone.applyTo('sTelephone'),

sState = new Ext.form.TextField({
width: 200,
allowBlank: false
}),
sState.applyTo('sState')

);

Ext.get('button_new').on('click', function(){
if (form_UserNew.isValid()) {
Ext.MessageBox.alert('Success', 'You have filled out the form correctly.');
return false;
}else{
Ext.MessageBox.alert('Errors', 'Please fix the errors noted.');
return false;
}
});

form_UserNew.render('UserNew');

},


} // var UserNew

As you can see I've already tried to return false, so preventing the default action when the form submits but that hasn't helped me much. Any suggestions, tips of solutions would be very appriciated since I've spend for over 6 hours to find a solution... :((