If after adding a new item to a grid with inline edit the save button is double-clicked (e.g. by accident) two new items are added instead of one. Right now, the only way to prevent this seems to be to check if an item is already contained in GridData at the top of the OnCreate-Handler and cancel if necessary. If a unique ID is not available yet (because it is created by the database when saving at the end of the handler) this means every Property has to be compared to check for equality. This is very annoying.
Please add a parameter "DisableWhileBeingHandled" to TelerikButtons and make this the default for the CommandButtons in a Grid. The Buttons should only accept clicks if the previous handling is finished.
Kind regards,
René
Hi René,
Here is an example how you can do this through the Enabled parameter. Since there are no native requests that a button does (unlike in older web stacks like WebForms/MVC) - there is nothing to tell the button it should stop being disabled and allow clicks again. Thus, it is the application that must implement such logic.
<TelerikButton OnClick="@DoWork" Enabled="@ButtonEnabled">
Do long work you must do only once
</TelerikButton>
@code{
bool ButtonEnabled { get; set; } = true;
async Task DoWork()
{
ButtonEnabled = false;
await Task.Delay(2000);
ButtonEnabled = true;
}
// Consider also adding a loading indicator, for example https://demos.telerik.com/blazor-ui/loader/button-integration
}
As for Grid integration - since we consider this behavior a valid bug that can be worked on, I have changed the post type to "Bug report". I also tweaked the title a bit to contain information about the scenario, so other interested parties can easily find it and vote for it. As you are the creator of the public post, you are subscribed and will receive email notifications when its status changes. Thus, you will be able to keep in track with the progress of the fix. We are prioritizing the bug fixes based on the community interest and demand and once we know which release will contain this fix, we will update its status in the feedback portal and you will be notified via email right away.
In the meantime, you can try a couple of other options apart from toggling the Enabled parameter of the button - the Grid offers a built-in loading panel over it to protect against long running operations. If that's not sufficient for your case, you can add a loading container of your own over it with the OnClick event the command buttons expose, and lower that flag in the corresponding handler (such a OnCreate) after you've done the work you need. Something else you can consider is adding the newly inserted item to the local data source (the Data collection) before doing the slow database operation, so the user sees an update immediately. Lastly, you can consider other modes than InCell for editing - only the InCell mode fires OnCreate immediately.
I hope you will find the above information and suggestions useful. If any further questions appear, please do not hesitate to contact us.
Thank you for choosing Telerik UI for Blazor!
Regards,
Nadezhda Tacheva
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.