PDA

View Full Version : markInvalid works for only a brief instant when triggered via keyup



Tod
24 Nov 2010, 7:08 AM
I want to use markInvalid to provide a warning to the user. The problem is that after marking the field, validate apparently comes along and clears the mark. Sample code below. If I type '5' or '12' into the field, it will flash with red but not stay that way. How can I fix this? Thanks,
-Tod



Ext.onReady(function(){
Ext.QuickTips.init();
function warn(form) {
if (form.getValue()===5 || form.getValue()===12) {
form.markInvalid('Warning');
} else {
form.clearInvalid();
}
}
new Ext.form.NumberField( {
renderTo: document.body,
maxLength: 4,
enableKeyEvents: true,
listeners: { keyup : warn }
})
});

Condor
25 Nov 2010, 8:13 AM
Configure the field with a validationEvent:'keyup' and write a 'validator' function that returns true or 'Warning'.

Tod
29 Nov 2010, 11:04 AM
But wouldn't that mean the form would not validate? I don't want validation, I want a warning. Based on the API description, this is exactly what markInvalid is supposed to be good for.

Condor
29 Nov 2010, 11:19 AM
Yes, but the next validation will clear the error (and the next validation is either when the field is blurred, or even every 100ms if you have monitorValid:true).

Tod
29 Nov 2010, 11:51 AM
I tried your suggestion, but its ends up validating, not warning. I'm confused -- do you think it is possible to issue a warning using the same UI as is typically used for validation, but have it be a warning only? E.g., user types 5 or 12 and gets warning message but can still submit form, change value, etc... Is there a workaround to the problem of the next validation clearing the error? Do you agree that markInvalid is not suitable for warning messages as a result?

Thanks Condor.
-Tod

Condor
29 Nov 2010, 11:21 PM
In that case I wouldn't use the error system. You could try using a FieldTip plugin to show the warning...