silverstripe/silverstripe-framework — pull request #2599 by tractorcow (2013-10-24 04:59:59+00:00)
Title: BUG / API - Change tracking for UploadField

This fix builds on top of the kind work done by @TomSpeak at https://github.com/silverstripe/silverstripe-framework/pull/2305

I've extended the jquery change tracker plugin to allow the form to be set to dirty. This means it can be told to stay dirty, even if it detects it's original fields haven't changed. This is necessary because some fields can be added to the form after initialisation. Another approach would be to detect changes to the form, but this would require a massive rewrite of jquery.changetracker. This approach does not allow for any un-dirtying of the form, so it's a one way only.

UploadField now communicates with the form by sending the 'dirty' event rather than adding the changed class. This is necessary because otherwise further form updates would remove the change class if a field is typed in, but then reverted to the original.

The login in UploadField also attempts to avoid unnecessary changes (such as uploading a file that already exists, and the user cancels the upload after the file exists notification).