Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6575465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:23:24+00:00 2026-05-25T15:23:24+00:00

This article by Sencha covers how to use the built in validation rules (presence,

  • 0

This article by Sencha covers how to use the built in validation rules (presence, length, format, inclusion, exclusion) and mentions that adding custom rules is easy, but doesn’t ever explain how to do it. I’ve googled high and low and read the sencha docs, but I can’t find anything on how to do it. Any Ideas?

http://www.sencha.com/learn/using-validations-and-associations-in-sencha-touch

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:23:25+00:00Added an answer on May 25, 2026 at 3:23 pm

    I think it’s one of the slight errors in the documentation. I got them to work by adding some code

    if (Ext.data) {
        Ext.data.validations.custom = function (config, value) {
            if (config && Ext.isFunction(config.fn)) {
                //this should be the model
                if (config.self) {
                    return config.fn.call(config.self, value);
                } else {
                    return config.fn(value);
                } 
            }
            else 
            {
                return false;
            }
        };
        Ext.data.validations.customMessage = "Error";
    }
    

    Then to add a validation to a model, add an object to the model’s validations array with type set to ‘custom’, e.g.

    { 
        type: 'custom', field: 'SomeField', message: "Your field is bad",
        fn: function (SomeFieldValueForThisInstance) {
           //Add some validation code.  The this pointer is set to the model object
           //so you can call this.get("SomeOtherFieldToCheck")
           //or any other instance method
    
           //if the field is good
           return true;
           //else
           return false;
        }
    }
    

    Update: @salgiza was right, there’s a few steps I forgot to mention in order to set the ‘this’ pointer correctly. If you look in the sencha touch code you’ll see that at the end of Ext.data.Model’s constructor it checks to see if there’s an init function defined on the object, and if so, calls it

            if (typeof this.init == 'function') {
                this.init();
    

    After you define your model you can add an init function to the prototype. In the function, iterate over the validations for the object and add a reference to this. This step should be done before any of the models are created.

        YourModel.prototype.init = function () {
            var i, len;
            if (this.validations) {
                for (i = 0, len = this.validations.length; i < len; i++) {
                    this.validations[i].self = this;
                }
            }
        };
    

    Then in the custom validation function above, just check if the config has a self pointer and if it does, call it with self. I’ve edited the code above to use self.

    Note: I don’t see the Model’s init function documented, so if sencha gets rid of it, you’ll have to add the this pointer to the model’s validations some other way.

    Sorry if this caused confusion for anybody.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This article on MSDN states that you can use as many try catch blocks
In this article, it is argued that Use Memcache if you frequently fetch random
This article here suggests to use -XX:+UseParNewGC To enable a parallel young generation GC
This article states that If your site is run on a shared Web server,
this article suggests you can use Color c = Color.decode(FF0096); however this understandably throws
This article about php form security: http://nedbatchelder.com/text/stopbots.html ... mentions a spinner as: The spinner
In this article http://www.jroller.com/eyallupu/entry/hibernate_the_any_annotation and also in this question How to use Hibernate @Any-related
In this article the author discusses the use of \@ to put correct spacings
Suddenly in this article (problem 2) I see a statement that C++ Standard prohibits
This article claims that each register has an intended purpose and more importantly, When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.