PDA

View Full Version : Validation Questions...



rymoore
11 Dec 2007, 1:58 PM
I have 2 questions about validation of FormPanel elements:

1) How can I mark & verify "Required Fields" in a form?
2) Can I create and assign multiple vtypes to a form element, or can each element only accept a single vtype?

Are there existing examples of either of these?

catacaustic
11 Dec 2007, 2:09 PM
Marking fields as required is up to you. You can add in whatever CSS or styling to the field labels as you wish, so it's up to you to mark them that way. You can also get a bit further into it and change the CSS on the fields themselves by adding a new class or style to them to make them look a bit different so people may realise. As for verifying required fields, there's all sorts of config options like allowBlank, minLength, maxLength that you can use to have the system know what's needed in them.

As far as using multiple vtypes, I don't think that's possible (but would be happy to be shown differently if it's actually allowed). I can't see how you'd want multiple vtypes in the one field though. As an example, what's the point of having email vtype and url types on the same field? They are seperate types, and are very different in use, so it doesn't make alot of sense in most applications to want both. Assuming that you do need something like that, the best thing to do is write your own function to validate the input and use the 'validator' config option when you set up the field. That way it'll use your own functions to determine what should and shouldn't be allowed in that field.

mdelanno
28 Nov 2008, 5:44 AM
Marking fields as required is up to you.
Look at http://extjs.com/deploy/dev/docs/?class=Ext.form.Field, config option itemCls, there is a sample of CSS rule for required field.

Jaitsu
28 Nov 2008, 6:14 AM
1) How can I mark & verify "Required Fields" in a form?


I think what you mean is how do you flag fields as required, so when you submit the form it checks that they're not empty?

You just need to use the
allowBlank: false config option when you created your field and then call a validation routine when you submit the form

Animal
28 Nov 2008, 6:48 AM
use http://extjs.com/deploy/dev/docs/?class=Ext.form.TextField&member=allowBlank

and http://extjs.com/deploy/dev/docs/?class=Ext.form.Action.Submit&member=clientValidation