Detecting value change on C5 image input field

Permalink
Howdy,

I'm using the asset library's image upload method, and need to be able to tell when a user has changed the selected image.

I have other input fields, drop downs, and wysiwyg areas that can detect any changes made by the user (I <3 jQuery), but I can't get it working for the image field.

From what I understand, when the image upload's input value changes, no event is triggered, as that could possibly lead to an infinite loop (that's what I've gathered least ways). I've been looking into modifying the core filemanager.js file and making the image field trigger a "change" event so that I can pick that up in my auto.js file. This would then open up the chance of an infinite loop, but not sure what else to do.

I don't really care to mod the core like that, so if anyone has any ideas/aid I'm all yours!

-Landson

Landson
 
Landson replied on at Permalink Reply
Landson
I've had a new thought on this. Thinking of just having a hidden field that contains the initial value of the image input field (the file's ID). Then once the user submits their data (that is, clicks add/save), the image fields are checked against their corresponding initial value fields to see if there were any changes. In this way, I wouldn't have to modify the core code (which, btw looks like I couldn't do anyways as the concrete/js/ccm_app files appear to all be compressed into one /js/ccm.app.js file).

The only foreseen issue with this technique would be if in any way different files can have the same ID value. Anyone know if this is possible?
JohntheFish replied on at Permalink Reply
JohntheFish
Doesn't solve your problem directly, but my Front End File Uploader addon fires a C5 event when a file is uploaded.
Mainio replied on at Permalink Reply
Mainio
If I need to do thing like this I usually just override the core JS. Great thing about JS, right...? :)

This example works with the image block editing form in 5.5.2.1:
$(document).ready(function() {
   var origFID = $("#ccm-b-image-fm-value").val();
   var _ccm_triggerSelectFile = ccm_triggerSelectFile;
   ccm_triggerSelectFile = function(fID, af) {
      if (fID != origFID) {
         alert("file changed! ("+origFID+","+fID+")");
         origFID = fID;
      } else {
         alert("file not changed...");
      }
      _ccm_triggerSelectFile(fID, af);
   }
});
JohntheFish replied on at Permalink Reply
JohntheFish
I see, I was looking at file changing after the upload, rather than before upload.
Mainio replied on at Permalink Reply
Mainio
Yeah, that can be done by hooking on to the "on_file_add" and "on_file_version_add" events I believe as well.

At least I understood he wanted to do some UI stuff after the fID is changed.
Landson replied on at Permalink Reply
Landson
It is indeed front-end changes. I have fields that need changing to a value of "update" when the user changes the image field's selected image. Both of you guys posted some good info (thanks a ton!), I'll be looking closer at it here and seeing how these options can be applied to my app.