Results 1 to 9 of 9

Thread: How to reset isDirty() for a controls

  1. #1
    Sencha Premium Member
    Join Date
    Feb 2013
    Location
    Bangalore, India
    Posts
    68
    Answers
    1
    Vote Rating
    1
      0  

    Default How to reset isDirty() for a controls

    Hi,

    I am checking before closing the window isDirty() flag.
    When i will save this value to me DB, that time also its giving same values.

    So how i will reset this value after saving to database.
    So that after saving if i will modify anything then i will get to know.

  2. #2
    Sencha - Documentation Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505
    Vote Rating
    253
      0  

  3. #3
    Sencha Premium Member
    Join Date
    Feb 2013
    Location
    Bangalore, India
    Posts
    68
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Hi,
    Thanks for your reply.

    still, i am not able to resolve my problem.
    it will help me if you provide an example about it.

  4. #4
    Sencha User
    Join Date
    May 2012
    Location
    Blumenau - Brazil
    Posts
    50
    Answers
    12
    Vote Rating
    8
      0  

    Default

    If I unsderstood, it's
    Code:
    yourForm.getForm().reset();
    or
    Code:
    yourForm.getForm().reset(yourRecord);
    --
    Jlio Csar Batista - blog - twitter
    Web Developer

  5. #5
    Sencha Premium Member
    Join Date
    Feb 2013
    Location
    Bangalore, India
    Posts
    68
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Actually me problem is like this.

    let's i have a text field control. If first time, i will check isDirty() status then i will get false.
    Now i will set some value to text field, if now i will check isDirty() status then i will get true.
    till now it's fine and no problem it is working for me.

    No i saved my text field value to some database.
    If now i will check isDirty() status then i should get false, but i am getting true.
    So i will achieve this or what i will do after saving for text field, so isDirty() status will reset..

    please help..

  6. #6
    Sencha - Documentation Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505
    Vote Rating
    253
      0  

    Default

    The example at the top of the form panel's API doc shows a reset button at the bottom of the form.
    http://docs.sencha.com/extjs/4.2.1/#...Ext.form.Panel

    Here is the same example with a "check if dirty" button.
    Code:
    Ext.create('Ext.form.Panel', {
        title: 'Simple Form',
        bodyPadding: 5,
        width: 350,
    
    
        // The form will submit an AJAX request to this URL when submitted
        url: 'save-form.php',
    
    
        // Fields will be arranged vertically, stretched to full width
        layout: 'anchor',
        defaults: {
            anchor: '100%'
        },
    
    
        // The fields
        defaultType: 'textfield',
        items: [{
            fieldLabel: 'First Name',
            name: 'first',
            allowBlank: false
        },{
            fieldLabel: 'Last Name',
            name: 'last',
            allowBlank: false
        }],
    
    
        // Reset and Submit buttons
        buttons: [{
            text: 'Reset',
            handler: function() {
                this.up('form').getForm().reset();
            }
        }, {
            text: 'Check to see if Dirty',
            handler: function () {
                console.log(this.up('form').isDirty());
            }
        }, {
            text: 'Submit',
            formBind: true, //only enabled once the form is valid
            disabled: true,
            handler: function() {
                var form = this.up('form').getForm();
                if (form.isValid()) {
                    form.submit({
                        success: function(form, action) {
                           Ext.Msg.alert('Success', action.result.msg);
                        },
                        failure: function(form, action) {
                            Ext.Msg.alert('Failed', action.result.msg);
                        }
                    });
                }
            }
        }],
        renderTo: Ext.getBody()
    });

  7. #7
    Sencha Premium Member
    Join Date
    Feb 2013
    Location
    Bangalore, India
    Posts
    68
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Hello, thanks for the reply.

    When i am doing reset for 'form' then all the controls get cleared.
    and isDirty() working fine.

    But my problem, i don't want to clear all the field. it should show all the value whatever i have before saving.
    after saving isDirty() should give false.
    If again i will modify anything then it should give true.

    how i will reset isDirty() flag only, i do not want to clear all the field value.

  8. #8
    Sencha Premium Member
    Join Date
    Feb 2013
    Location
    Bangalore, India
    Posts
    68
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Whether sencha provide any method for 'form' to call "resetOriginalValue()" for all the controls of form.

    i mean is there any way or method to get all the controls item id to call "resetOriginalValue()" method.
    or any method which will call "resetOriginalValue()" method for all the controls.

  9. #9
    Sencha - Documentation Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505
    Vote Rating
    253
      0  

    Default

    You might look at loading the form with a record using loadRecord. When you reset() a form that was loaded with a record you can choose whether to reset completely or just back to the values loaded from the record.

    When changes occur in the form you can use updateRecord. And instead of using the form's submit action you can give the record a proxy and use the record's save() method to save values back to the server.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •