I've got a setup wherein I store files in a database, and I can interact with these in my DataSource, fileDS. Users are allowed to delete files from this database.
I'm having a problem if a user deletes a file, and then another part of the code tries to access that file through a saved entry in another database (accessed through another DataSource jobDS). Entries in jobDS are valid even if the file they reference has been deleted, but it is invalid for them to try to use that deleted file again.
I have a custom CanvasItem which displays these files as a StaticTextItem. The value for the CanvasItem contains the filename for display purposes and the ID for later retrieval. I'm trying to find a way to add a validator for my CanvasItem which can validate the IDs if the user tries to use it.
What I have is this:
but this isn't working because the fetchRecord is executed asynchronously. Is there some other way I can validate an ID?
1) Is there a way to do a synchronous call on the client (like the above)?
2) It doesn't make sense that a server validator would live in my fileDS since its own primaryKey IDs are obviously valid.
3) It doesn't make sense for a validator to be in my jobDS since people will want to inspect old entries even if the file used to create them has since been deleted.
Now obviously I can throw an error later where I try to use the file on the server. I'm just wondering if there's a way to do this in a regular validator since it seems like such a simple thing to want to validate.
I'm having a problem if a user deletes a file, and then another part of the code tries to access that file through a saved entry in another database (accessed through another DataSource jobDS). Entries in jobDS are valid even if the file they reference has been deleted, but it is invalid for them to try to use that deleted file again.
I have a custom CanvasItem which displays these files as a StaticTextItem. The value for the CanvasItem contains the filename for display purposes and the ID for later retrieval. I'm trying to find a way to add a validator for my CanvasItem which can validate the IDs if the user tries to use it.
What I have is this:
Code:
validators: [ { type:"custom", condition:function(item,validator,value,record){ if(value == null) return true; var valid = false; fileDS.fetchRecord(value.ID,function(dsResponse,data,dsRequest){ valid = data.length > 0; }); return valid; }, errorMessage:"File not in database!" } ],
1) Is there a way to do a synchronous call on the client (like the above)?
2) It doesn't make sense that a server validator would live in my fileDS since its own primaryKey IDs are obviously valid.
3) It doesn't make sense for a validator to be in my jobDS since people will want to inspect old entries even if the file used to create them has since been deleted.
Now obviously I can throw an error later where I try to use the file on the server. I'm just wondering if there's a way to do this in a regular validator since it seems like such a simple thing to want to validate.
Comment