1. #1
    Sencha User thesilentman's Avatar
    Join Date
    Apr 2007
    Location
    Athens, Greece
    Posts
    232
    Vote Rating
    2
    thesilentman is on a distinguished road

      0  

    Default isDirty works fine on empty form but returns true after form.load

    isDirty works fine on empty form but returns true after form.load


    Hello,

    I just built ext from the SVN and was testing the monitoring and isDirty.

    I wanted to accomplish a 'Save' button when the data in a form isValid && isDirty.
    So I tuned on monitoring of the form and check for the event like this.

    HTML Code:
    form[tmpdlgid].on('clientvalidation', function(){
    	if(form[tmpdlgid].isDirty() && form[tmpdlgid].isValid()){
                         console.debug (form[tmpdlgid].isDirty());
                         submitbutton[tmpdlgid].enable();
    	}
    });
    This works perfectly with an empty form. I have to make some change and also have valid data in the fields. After that my button is enabled.

    However, when on the same form, using form load...
    HTML Code:
    console.debug('got an ID, loading...');
    form[dlgid].stopMonitoring();
    form[dlgid].load({
    	url : 'jsonform.php',
    	waitMsg : 'loading data...',
    	params : {'id'  : id}
     	});
    form[dlgid].startMonitoring();
    ...isDirty is always true. Note that I also tried stopMonitoring before load and startMonitoring after.


    Looks like a bug?

    [EDIT]
    Either this is by design or a bug..

    I put:
    HTML Code:
    console.debug('isDirty -> new value: '+String(this.getValue())+' / old value: '+String(this.originalValue));
    into ext at the isDirty function.

    This is what I got in Firebug:

    isDirty -> new value: jim / old value:

    Means that the isDirty function is checking this.originalvalue which is empty while it should have the loaded data which in this case is 'jim'. Is this by design? Shoudn't dirty mean any change since the original loaded data?

  2. #2
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    The config option "trackResetOnLoad" will reset originalValues when forms are loaded if set to true.
    Jack Slocum
    Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum
    jack@extjs.com

  3. #3
    Sencha User thesilentman's Avatar
    Join Date
    Apr 2007
    Location
    Athens, Greece
    Posts
    232
    Vote Rating
    2
    thesilentman is on a distinguished road

      0  

    Default


    Thanks Jack!!!

    I looked into the source code and saw how you did it. Now I understand.
    Thanks for your reply!!

    Frank

  4. #4
    Ext JS Premium Member neongrau's Avatar
    Join Date
    Mar 2007
    Posts
    249
    Vote Rating
    0
    neongrau is on a distinguished road

      0  

    Default


    does this mean trackResetOnLoad and the isDirty() support are both tied to the originalValue used for .reset()

    or: when i load a record with trackResetOnLoad=false the isDirty() will only check the current value against the inital empty state?

    if so, i guess some shortcut to explicitly clear a form or a field would be useful.

  5. #5
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    Yes, originalValue is the original value.
    Jack Slocum
    Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum
    jack@extjs.com

  6. #6
    Developer... jon.whitcraft's Avatar
    Join Date
    Mar 2007
    Posts
    391
    Vote Rating
    0
    jon.whitcraft is on a distinguished road

      0  

    Default


    Thanks this helped.
    Jon
    Lead Internal Application Engineer - SugarCRM
    h2ik.co

  7. #7
    Ext JS Premium Member milanz's Avatar
    Join Date
    Aug 2007
    Posts
    47
    Vote Rating
    0
    milanz is on a distinguished road

      0  

    Default


    .. Edit ..

    I think there needs to be a way to reset a form's isDirty property to false and reset each fields originalValue to the current values. Here's why:

    1. Form loads (all fields are clear, adding new record)
    2. User fills in the fields and submits the form
    3. Form submit was successful, now hide/show certain buttons to "maintain" that record. I.e. Remove the "Insert Record" button and show the "Update Record" button.

    At this point any call to reset() should reset to the last successful saved state without having to reload the record after the successful save callback. Something like "form.resetIsDirty()" which would reset the dirty state of each field and redefine each fields originalValue to the current value. This would be very helpful.

    I also agree with neongrau that there should be some method to explicitly clear all fields regardless of their originalValue.

  8. #8
    Ext User
    Join Date
    Nov 2007
    Posts
    21
    Vote Rating
    0
    PaddyInDaGorge is on a distinguished road

      0  

    Default check event fires before originalValue = getValue()

    check event fires before originalValue = getValue()


    This thread has been helpful for my understanding of how trackResetOnLoad works. I am, however, seeing some strange behavior with checkboxes on my form.

    My form consists of checkboxes and textboxes. I have the checkbox check event wired up to the same handler as the textbox blur event:

    PHP Code:
    function onFormValueChanged(source){
        if (
    source.isDirty()) {
            
    // do stuff...
        
    }

    If I set a breakpoint on the first line, I notice that as the form is loading the checkboxes whose value changes during load return isDirty() = true. This is not the case for the textboxes. Interestingly, if I instead handle the blur event on the checkboxes isDirty() = false.

    I might be satisfied with just using the blur event for all the form controls, but I need to invoke onFormValueChanged when the user merely checks the checkbox and doesn't leave focus.

    I did set a breakpoint on ext-all-debug.js, line 27324. For the checkboxes, originalValue does get set to getValue() when I have trackResetOnLoad = true; but the problem is that this assignment happens *after* the check event fires during form load. With the blur event the assignment happens before the event fires.

    Is this by design? If so, what's a good work-around? It seems to me that trackResetOnLoad may not be working properly with checkboxes, but I'm still largely an ExtJS noob, so perhaps I'm missing something here.

  9. #9
    Ext User
    Join Date
    Nov 2007
    Posts
    21
    Vote Rating
    0
    PaddyInDaGorge is on a distinguished road

      0  

    Default


    I figured out an OK work-around: wire up the check event handlers in a BasicForm.actioncomplete event handler. This solves the problem for now, but it seems like I shouldn't have to do this.

  10. #10
    Ext JS Premium Member
    Join Date
    Mar 2010
    Posts
    21
    Vote Rating
    0
    Maarten76 is on a distinguished road

      0  

    Default


    Quote Originally Posted by milanz View Post
    .. Edit ..

    I think there needs to be a way to reset a form's isDirty property to false and reset each fields originalValue to the current values. Here's why:

    1. Form loads (all fields are clear, adding new record)
    2. User fills in the fields and submits the form
    3. Form submit was successful, now hide/show certain buttons to "maintain" that record. I.e. Remove the "Insert Record" button and show the "Update Record" button.

    At this point any call to reset() should reset to the last successful saved state without having to reload the record after the successful save callback. Something like "form.resetIsDirty()" which would reset the dirty state of each field and redefine each fields originalValue to the current value. This would be very helpful.

    I also agree with neongrau that there should be some method to explicitly clear all fields regardless of their originalValue.
    Is something like this already realized in Ext 2 / 3? Because I'm having the same problem..

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."