Detecting a Change Anywhere in the Form after Opened

DKinsley

02-06-2016

Is it possible to script to detect if any change occurred since the form was opened? For example if one of the text objects now has different text or no text or if a check box is now unchecked or a dropdown slection has changed?

Accepted Solutions (1)

Accepted Solutions (1)

_Bruce_Robertson

MVP

09-06-2016

Hi Don,

Not sure if its the forum or not but you need a double equals,

if(event.target.dirty == true){

or, just leave the == true off

if(event.target.dirty){

Bruce

Answers (6)

Answers (6)

DKinsley

07-06-2016

Bruce,

I guess I still don't know how to write this script. Is it something like this?

Form1:preSave - (JavaScript, client)

if(event.target.dirty = true){

Subform2.textfield2.rawValue = "Changed";

}

And I can reset the textField2 to blank each time the form is opened.

I can't get this to work. What am I missing?

DKinsley

07-06-2016

Bruce,

What I plan to use this for is updating the connected database. When the form is closed, if there have been any changes to the form, the form data is exported to the database; updating the database to match the form. If no changes have occurred since the form was opened, no export to the database occurs.

As far as your question if the user makes a change and then outs it back to the original value, reste the textField would be great but not absolutely necessary. The database data would still match the form.

Using the PreSave event seems to make sense so i will do some testing to see if I can get it to work.

I will mark your answer correct as soon as i can get this test done. Thank you for your help with this project.

_Bruce_Robertson

MVP

07-06-2016

Hi Don,

I think you will need to do this in the preSave event.  The dirty flag is a per session thing, I guess it is what drives the "Do you want to save changes to ... before closing" message if you attempt to close a form without saving the changes.

So the dirty flag is always false at docOpen.

Will you need to reset the textField if the user changes the form values back to the original values (or blanks them out)?

Bruce

DKinsley

06-06-2016

Hello Bruce,

Sorry - I don't know what you mean. I want to beable to detect a change to any object on the form after the form is opened. So for example, have a text field object with a script that states if a change is made to any of the objects on the form, this text field's rawValue will equal "Changed".

So would I put your script in the Form docReady event? Something like this?

if(event.target.dirty){

textField.rawValue = "Changed";

}

Thank you for your help with this.

-Don