Skip to content

Commit b7ecab3

Browse files
docs(upload): OnClear event
1 parent 202e212 commit b7ecab3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

components/upload/events.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This article explains the events available in the Telerik Upload for Blazor:
2020
* [OnSuccess](#onsuccess)
2121
* [OnError](#onerror)
2222
* [OnCancel](#oncancel)
23+
* [OnClear](#onclear)
2324

2425

2526
## OnSelect
@@ -665,6 +666,50 @@ You can cancel the event based on a condition (for example, some information abo
665666
@[template](/_contentTemplates/common/general-info.md#event-callback-can-be-async)
666667

667668

669+
## OnClear
670+
671+
The `OnClear` event fires when the user clicks the Clear button which is available when `AutoUpload="false"`. You can prevent the action on a condition.
672+
673+
@[template](/_contentTemplates/upload/notes.md#events-files-carry-client-validation-info)
674+
675+
>caption Handling the OnClear event and cancelling it on condition
676+
677+
@[template](/_contentTemplates/upload/notes.md#see-controller-sample-in-overview)
678+
679+
````CSHTML
680+
@inject NavigationManager NavigationManager
681+
682+
<TelerikUpload SaveUrl="@SaveUrl"
683+
RemoveUrl="@RemoveUrl"
684+
OnClear="@OnClearHandler"
685+
AutoUpload="false">
686+
</TelerikUpload>
687+
688+
@code {
689+
async Task OnClearHandler(UploadClearEventArgs e)
690+
{
691+
// cancel the action if there is exactly 1 file selected
692+
if(e.Files.Count == 1)
693+
{
694+
e.IsCancelled = true;
695+
}
696+
697+
foreach (var file in e.Files)
698+
{
699+
Console.WriteLine($"The user cleared this file before it was uploaded: {file.Name}");
700+
}
701+
}
702+
703+
// a sample way of generating the URLs to the endpoint
704+
public string SaveUrl => ToAbsoluteUrl("api/upload/save");
705+
public string RemoveUrl => ToAbsoluteUrl("api/upload/remove");
706+
707+
public string ToAbsoluteUrl(string url)
708+
{
709+
return $"{NavigationManager.BaseUri}{url}";
710+
}
711+
}
712+
````
668713

669714

670715
## See Also

0 commit comments

Comments
 (0)