PDA

View Full Version : JS Problem (or I am the problem?)



mapo
20 Aug 2007, 11:14 AM
Here the form's isValid function


isValid : function(){
var valid = true;
this.items.each(function(f){
if(!f.validate()){
valid = false;
}
});
return valid;
},


the f.validate() function always returns true -i.e. the fields are valid- (I debugged it with Firgebug, I even stored validate()'s result in a local variable to see it better, and it is true!), but the code ALWAYS enters the if block and sets valid = false. I am using Firefox 2.0.0.6 with Ext 1.1... Either Firefox, JS, Windows or my CPU must be broken :)! Any idea? Ah, just to make it more compelling, I also tried


if(f.validate()){
valid = false;
}


and of course it enters the if block (in this case correctly)..

kenisfam
20 Aug 2007, 12:06 PM
Hi , im totally new my self,

but i might know the answer:

(sorry if its not the solution)
I think because you declared valid with var in the function its only available in that function ,

take var of it,
it should do the trick .



isValid : function(){
valid = true;// taken var off
this.items.each(function(f)
{ // this is another function
if(!f.validate()){
valid = false;
}
});
return valid;
},


Luck

mapo
21 Aug 2007, 12:15 AM
Thank you kenisfam,

a reboot (i.e. the typical computer scientist's solution) fixed the problem. No idea why it happened, it could have been some firebug problem as well...

Thanks