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

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,

function warn(form) {
if (form.getValue()===5 || form.getValue()===12) {
} else {
new Ext.form.NumberField( {
renderTo: document.body,
maxLength: 4,
enableKeyEvents: true,
listeners: { keyup : warn }

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

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.

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).

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.

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...