Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS: form validation against model

I'm learning ExtJS, and I came across two different concepts, that seem logically connected to me.

  1. Model classes can specify custom validation methods on their fields.
  2. Model instances can be loaded into, and retrieved from Forms.

My question is:

  1. Is it possible to have the form use the model's validation setup to validate what the user enters and show realtime feedback?
  2. If the answer to 1 is No, then is there any other way to set up realtime validation in the form?

Thanks

like image 922
jrharshath Avatar asked Sep 04 '11 16:09

jrharshath


2 Answers

  1. As Molecule Man says, there is no built-in functionality for this, however...

  2. This seems to be a commonly required feature (and something that makes Ext JS 4 look a little half-baked), and other people have come up with various solutions:

    • Form <-> Model binding
    • ExtJS4: Form validation via Model binding

The first suggestion modifies the Ext.form.field.Base class to allow binding a form field to a Model field, and to validate the form field against validations defined on the form field as well as those defined on the bound Model field.

I'm just about to test the first suggestion, may post an update on how it goes...

like image 190
Oliver Coleman Avatar answered Oct 19 '22 12:10

Oliver Coleman


1. Is it possible to have the form use the model's validation setup to validate what the user enters and show realtime feedback?

There is no built-in functionality for model's realtime validating. However, there is better way then using model's validation.

2. If the answer to 1 is No, then is there any other way to set up realtime validation in the form?

Yes, there is.
Form's fields support vtype config (More info can be found here). By default the fields would be validated everytime the fields' value would change (if you want to turn off this behaviour set field's validateOnChange config to false).

Check out docs (the Validation section and the Example usage section) for more info.

like image 34
Molecular Man Avatar answered Oct 19 '22 14:10

Molecular Man