PDA

View Full Version : why a form.isValid() fail?



fother
25 Jan 2008, 3:03 PM
i set manualy for my input
field.markInvalid('text'); render the style.. and a message correctly

but when i press a submit button..

i call the function that valid my form, but the resulf for this form1.form.isValid() is true

why?

thanks

sfwalter
25 Jan 2008, 4:07 PM
Just marking a field invalid, doesn't actually make it invalid as I found out a while ago. One option is to use a validator function on the component in question. For example:

{
xtype:'textfield'
validator: function(value) {
if(value=="1") return "value can't be one";
return true;
}

Or a little hack I have done is something like this:

field.markInvalid("field is not valid")
field.isValid = function() { return false; }

scott.

fother
25 Jan 2008, 4:14 PM
dont solve my problem...

halkon_polako
27 Jan 2008, 9:18 AM
With validator function on textfield you don't have to call markInvalid. That function (markInvalid) is called for you by Ext if validator function returns a string message (like sfwalter example).
If stills don't solve your problem, please, provide some additional code so we can see what you are doing.

fother
29 Jan 2008, 10:23 AM
I caught this code in this forum .. But dont remember the URL


/* Funcao responsavel por validar dados no formulario */
Ext.override(Ext.form.BasicForm, {
areFieldsValid: function() {
var valid = true;
this.items.each(function(f){
if(f.el.hasClass(f.invalidClass)){
valid = false;
}
return valid; // Abort iteration at first invalid Field!
});
return valid;
}
});

and use this for validat your form

form1.form.areFieldsValid()

work 100% :D

If someone knows the author of the code. Please put your name