sencha touch form validation - Sencha Touch : Login Form with validation

Sencha Touch : Login Form with validation

Posted on

sencha touch form validation - Sencha Touch : Login Form with validation

In today’s post I am going to show you how to create a simple form in Sencha Touch with validation. I will create a simple Login form with username and password field and create a model which contains fields and validation logic.

Once user submit form for login, we get the validation logic and see if all the field get passed against our model validation logic, if no then will show error message alert and make the field highlighted in red border. So lets start first by creating Model. Pay attention to validations array, its an array of all validation rules that we want to apply for our model fields.

Now, create a LoginForm by extending FormPanel.

Take a close look at login button handler. First, we are creating the model object and then calling validate() method on it. Calling validate methods return Ext.data.Errors object. We can call isValid() function to see if form contain any error on not.

Output:

On Initial launch of form…

011 - Sencha Touch : Login Form with validation

If form contains any error…

021 - Sencha Touch : Login Form with validation

I hope you enjoy the post. Happy Coding 🙂

Source techzoo.org