Hi everyone,
I made a database collection where a user can upload a picture. Now, I want to add the feature this picture can be deleted and if necesarry be changed by another picture.
Hope someone can help me out
Best,
Ruben
Hi everyone,
I made a database collection where a user can upload a picture. Now, I want to add the feature this picture can be deleted and if necesarry be changed by another picture.
Hope someone can help me out
Best,
Ruben
Have a look at remove in Wix Data.
https://www.wix.com/corvid/reference/wix-data.html#remove
Or Wix Dataset.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#remove
You might also want to refresh your dataset if it is connected to something on your website.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#refresh
Hi @givemeawhisky ,
I’m trying to work on a similar issue and have managed to compile the below code but with no success. Any possibility you could review and provide help?
Fyi, I’m on a page where I accept users to upload some documents. After uploading (and page refresh), I need to allow a user to delete the document (stored as a field in database with ‘Document’ datatype) using a button.
And I’m trying to delete just one field (field key = ‘message1_doc’) and not the entire row of record (containing other fields).
export function deletedoc1button_click(event) {
$w(“#dataset1”).onReady(() => {
$w(‘#dataset1’).refresh()
$w(‘#dataset1’).getCurrentItem().message1_doc.remove()
$w(‘#dataset1’).save()
})
}
When published, nothing happens on clicking of the button. I’m not sure if this code requires page.onready to be called first. In fact, if I replace this field with any other field (with number or text datatype) in the same database (or collection)… it doesn’t work for them either.
Thanks.
@rishalsharma I think this is all you need. It deletes the current row from the collection, as opposed to clearing a cell’s value in that row. For that you’d want to setFieldValue() then save().
export function deletedoc1button_click(event)
{
$w('#dataset1').remove();
}
I suspect you may well be out of luck if you wanted to delete the file itself in addition to the reference to it in the database.
@lee1 ouch. That’s going to hurt me. Nevertheless, thanks for the response.
I’m going through the API reference documentation for proper syntax of setFieldValue() but cannot seem to get that to work either (of course, I’m trying on another text field called message_lastname).
Tried both versions of below code but with no luck.
export function deletedoc2button_click(event) {
$w(‘#dataset1’).getCurrentItem().setFieldValue(“message_lastname”,“Dodo”);
$w(‘#dataset1’).save()
})
}
export function deletedoc2button_click(event) {
$w(‘#dataset1’).getCurrentItem().message_lastname.setFieldValue(“Dodo”);
$w(‘#dataset1’).save()
})
}
export function deletedoc2button_click(event)
{
$w('#dataset1').setFieldValue('message_lastname', undefined);
$w('#dataset1').save();
}