openannotation / annotator

Annotation tools for the web. Select text, images, or (nearly) anything else, and add your notes.
http://annotatorjs.org
Other
2.67k stars 532 forks source link

Does anyone else have a problem with deleting/updating an annotation? #703

Open ECannon opened 5 years ago

ECannon commented 5 years ago

Hi, I am using annotator v 2., I have annotator saving annotations and loading them again on page load, however when I try to delete or update the annotation I get an error 'annotation must have an id for delete()' and similar for update.

Has anyone had any problems with this before?

P.S my backend is fine and set up as per the documentation (works with postman) but I must be missing something on the front end, any help is appreciated.

Thanks.

tilgovi commented 5 years ago

The annotations must have an id property to delete them, according to the way the storage system is written. If you are returning annotations from your server on page load, make sure you assign each of them an id property.

https://github.com/openannotation/annotator/blob/master/src/storage.js#L599

ECannon commented 5 years ago

Thanks for your timely reply. When I create an annotation I am storing them in mongoDB which will automatically create an id, however this id is not being sent in the url when I click the delete (x) on the annotation. When I am creating an annotation and then storing the annotation there is also no id being sent in the request body, only quote, ranges, text and uri. I would not have the uri in the body only that I included it on the client side. Do i have to do the same with the id?

tilgovi commented 5 years ago

You need to include the id in the body. If I remember correctly, MongoDB might add an _id field, but you will have to format this as id or change the storage adapter to suit your needs.

After you save an annotation, you will want to also update the new annotation by returning the annotation, with its new id.

ECannon commented 5 years ago

That's exactly it, thank you!