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

  • SEARCH
  • Home
  • 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 6906037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:15:28+00:00 2026-05-27T08:15:28+00:00

How do I call a beforeSave method (i.e. a method that is triggered every

  • 0

How do I call a beforeSave method (i.e. a method that is triggered every time a model record is added, updated and/or saved) for a Sencha Touch MVC Model?

  • 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-27T08:15:29+00:00Added an answer on May 27, 2026 at 8:15 am

    (assuming Sencha Touch 1.x)

    As far as I know there is no event that tells you that the data WILL be changed but hasn’t changed yet.
    However, the post-change event is called ‘datachanged’. If you just need to know that your data is changed (and not BEFORE it is changed), add a listener for this ‘datachanged’ event and discard the rest that I have written.

    However, if you really need a ‘beforedatachanged’ event, read on:

    You could implement your own event(and call it ‘beforedatachanged’) by using Ext.override to override the Sencha behavior and trigger your new event before the data is actually changed.

    It might sound difficult, but it really is not:

    First check this out:
    http://docs.sencha.com/touch/1-1/source/AbstractStore.html
    Go and find “onBatchComplete”, you’ll see that it fires the ‘datachanged’ event:

    /**
     * @private
     * Attached as the 'complete' event listener to a proxy's Batch object. Iterates over the batch operations
     * and updates the Store's internal data MixedCollection.
     */
    onBatchComplete: function(batch, operation) {
        var operations = batch.operations,
            length = operations.length,
            i;
    
        this.suspendEvents();
    
        for (i = 0; i < length; i++) {
            this.onProxyWrite(operations[i]);
        }
    
        this.resumeEvents();
    
        this.fireEvent('datachanged', this);
    },
    

    Before the “this.suspendEvents();” you have to fire your own custom event, because after that, the operations are executed.

    To override this, write something like this in your application:

    Ext.override(Ext.data.AbstractStore,
    {
        onBatchComplete: function(batch, operation)
        {
            var operations = batch.operations,
                length = operations.length,
                i;
    
            this.fireEvent('beforedatachanged', this);
    
            this.suspendEvents();
    
            for (i = 0; i < length; i++) {
                this.onProxyWrite(operations[i]);
            }
    
            this.resumeEvents();
    
            this.fireEvent('datachanged', this);
        },
    });
    

    Then you need to listen to the beforedatachanged event in your model code and you’re all set.

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

Sidebar

Related Questions

I call addNotify() method in class that I posted here. The problem is, that
I have a before_save method that I call that renames an uploaded image. before_save
How can I call the log() function inside the model beforeSave() function? All three
I have a model called Details that contains a method that updates some attributes
I have a user model that has_one membership (active at a time). For auditing
I call an ajax enabled wcf service method , <script type=text/javascript> function GetEmployee() {
I've the following model and I want to execute a method on save and
I call this method on form load ivent GetProducts( ); This Query works fine
Call me stupid but this thing has been eating away my productive time like
I call an image using the displayMainImage.php link below and that works fine, it

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.